Skip to content

Recipes

Working scripts for the things people actually build. Every one is complete — copy it onto an object and it runs.

New to this? Start with Your first script.

Things you click and walk into

Doors and switchesa door that opens, closes itself, or is driven by a switch across the room
Triggers and zonesgreeters, pressure plates, checkpoints, hazards
Moving thingslifts, platforms, patrols, conveyors, projectiles

Things players hold

Pickups and carryingpick it up, pose it, put it down, hand out copies
Weapons and combata complete weapon: recoil, cone, ammunition, reloading
Poses and animationsmake a pose in the animator and play it on somebody
Damage and destructionbreakable props, player health, respawning

Talking to players

Menus and HUDspanels, pages, live numbers, world prompts
Shops and currencya counter, a balance, goods that reach a hand

The world itself

Effects and atmospherefire, smoke, lamps, weather, storms
Sound and musicone-off noises, loops, distance, ambience
Terrain and blockssculpting ground, mining, generated structures
Building and survivalpieces players raise, support, resources that regrow

Plumbing

Saving datawhat survives a restart, and how to store it
Talking between scriptsevents, public channels, tags

Five habits worth copying

They show up in nearly every recipe here.

Check before you use. Anything that can answer nil deserves the check, and the shape is always the same:

luau
local part = self:part("hinge")
if not part then return end

Ask the engine, do not remember. self:held_at(), player.holding, self:get(...) — a local copy of the world's state goes stale the moment something happens by a route your script does not run.

Act on the change, not on the tick. A timer that writes the same properties every second spends the region's budget for nothing.

luau
if should ~= current then
    current = should
    apply(current)
end

Save a timestamp, not a countdown. world:clock() keeps running while the world is off, so a stored moment is still true after a weekend. A countdown only moves while somebody is ticking it.

Cancel the timer you are replacing. Otherwise clicking twice leaves two of them, and the second one fires into a world that has moved on.

See also

Hungrit scripting documentation.