Skip to content

Touch, prompts and zones ​

How players interact with the world: touching parts, clicking them, pressing a key near them, walking into an area. Much of it needs no code at all.

Gameplay with no code ​

Put one of these inside a part (Insert Object > Gameplay (no script needed)), set a number or two in the Inspector, and press Play. An obby's whole kit is a few inserts.

ObjectWhen a player touches its partSettings
TeleporterThey appear standing on another partdestination (a part). Two Teleporters that name each other make a two-way portal
HazardIt takes health at once, and again each second they staydamage (100, a whole bar: deadly at once; negative heals)
CheckpointFrom now on they come back here after dying-
PickupIt adds to their stat and its part disappears for a whilestat ("Coins"), amount (1), respawnTime (10 s; 0 = never)
BoostMore walk speed and jump power for a whilewalkSpeed, jumpPower, duration (seconds)

And four that need no player to touch them:

ObjectWhat it doesSettings
MotionIts part (and the parts inside it) moves and turns by itself: a moving platform, a lift, a spinning blade, a swinging hammermove (a vec3 of units), turn (degrees), pivot, time (each way), pause (at each end), delay, reverses, looped, smooth, relative
SpawnerMakes a copy of a part or a Model every few seconds where its part is: a dropper's ore, falling rockstemplate, interval, limit (at once), lifetime, velocity, relative
SeatA player who touches it sits down; jumping stands them upoccupant, sat, left, sit(player), stand()
VehicleSeatA seat that drives: the sitter's keys turn the motor Hinges of its Model. Insert > Vehicle (car) makes one ready to drivemaxSpeed, torque, turnSpeed; read throttle, steer

The server does all of it, so a player can't collect a coin or skip lava by cheating.

Adding to them with a script ​

Each fires triggered(player) when it acts, and an event with a more telling name: Teleporter teleported, Hazard hurt, Checkpoint reached, Pickup collected, Boost boosted. A script adds to a brick without replacing it:

lua
world.Coin.Pickup.collected:connect(function(player)
    print(player.name .. " has " .. player.stats.Coins .. " coins")
end)

world.Finish.Checkpoint.reached:connect(function(player)
    chat.send(player.displayName .. " reached the finish!")
end)

local lava = new("Hazard", world.Floor)   -- and they are made like anything else
lava.damage = 25

Every one has enabled.

Touching ​

touched fires when something touches a part - a player's character or another part. touchEnded when it stops.

lua
local pad = world.SpeedPad
pad.touched:connect(function(hit)
    local player = players.fromPart(hit)
    if player then
        player.walkSpeed = 40
    end
end)

touched fires many times while someone stands on a part. To act once, remember who is on it:

lua
local onPad = {}
pad.touched:connect(function(hit)
    local player = players.fromPart(hit)
    if not player or onPad[player.name] then return end
    onPad[player.name] = true
    player:damage(10)          -- once, not every frame they stand there
    task.wait(1)
    onPad[player.name] = nil
end)

Clicking: Clickable ​

Put a Clickable in a part and players can click (or tap) it:

lua
local button = world.Button
local clicker = new("Clickable", button)
clicker.maxDistance = 20   -- units

clicker.clicked:connect(function(player)
    print(player.name .. " pressed the button")
end)

Pressing a key: Prompt ​

A Prompt in a part shows a small panel - "[E] Open" - to players near it. Pressing the key, or clicking or tapping the panel, fires triggered on the server:

lua
local door = world.Door
local prompt = new("Prompt", door)
prompt.text = "Open"
prompt.key = "E"
prompt.maxDistance = 8

prompt.triggered:connect(function(player)
    door.canCollide = false
    door.transparency = 0.7
    task.wait(3)
    door.canCollide = true
    door.transparency = 0
end)

Only the nearest Prompt in reach shows, and the server checks the player really is in reach.

Text over a part: Billboard ​

lua
local sign = new("Billboard", world.Shop)
sign.text = "SHOP"
sign.offset = 2            -- units above the part's top
sign.textSize = 24
sign.maxDistance = 80

It always faces the camera, stays the same size on screen, and fades when something stands between it and the camera. For writing on a face of a part, use a Sign (text, face, textColor, fit).

Areas: Zone ​

A Zone makes its part an area that says who comes in and goes out - a shop, a safe zone, a finish line. KHIM Engine makes the part see-through, anchored and walk-through when you add one.

lua
local zone = world.ShopArea.Zone

zone.entered:connect(function(player)
    net.send(player, "openShop")
end)

zone.left:connect(function(player)
    net.send(player, "closeShop")
end)

print(#zone:players() .. " in the shop")
MemberWhat it is
entered, leftA player came in / went out
partEntered, partLeftA loose part came in / went out
players(), parts()Who and what is inside now
contains(position or player or part)Whether it is inside
enabledOn or off

A player is inside when the line through their body, feet to head, passes through the part - so a flat pad on the floor works as well as a tall box.

Timers ​

A Timer fires after a time, once or again and again - a round's clock, a bomb's fuse, a wave of enemies:

lua
local timer = new("Timer", world)
timer.interval = 30
timer.repeats = true
timer.fired:connect(function()
    chat.send("A new wave is coming!")
end)
timer:start()
-- timer.timeLeft, timer.running, timer:stop()