Lava that kills
Tag a part "Lava" in Studio and touching it kills the player.
local world = require("@usbx/world")
world.tagged("Lava").touched:connect(function(part, player)
if player then
player:kill()
end
end)Tag a part "Lava" in Studio and touching it kills the player.
local world = require("@usbx/world")
world.tagged("Lava").touched:connect(function(part, player)
if player then
player:kill()
end
end)Players walk up and press the interact key, and the door slides open.
local world = require("@usbx/world")
local math3d = require("@usbx/math")
local door = world.find("Door")
door.prompt = { text = "Open" }
door.interacted:connect(function()
door:tween({ position = door.position + math3d.vector3.new(0, 10, 0), duration = 1 })
end)Players pick up tokens that respawn. The count shows on the scoreboard and is saved between visits.
local world = require("@usbx/world")
local state = require("@usbx/state")
local schema = require("@usbx/schema")
local data = require("@usbx/data")
data.profile_schema(schema.struct({ tokens = schema.number() }))
local tokens = state.create_per_player("tokens", 0, schema.number(), { leaderboard = { label = "Tokens" } })
data.save_in_profile(tokens, "tokens")
world.pickup("Token", function(_token, player)
tokens:increment(player)
end, { respawn = 10 })Shows a welcome message to each player who joins.
local players = require("@usbx/players")
local ui = require("@usbx/ui")
players.joined:connect(function(player)
ui.toast(player, { title = "Welcome, " .. player.name, text = "Find all 10 hidden tokens!" })
end)A button that trades 10 tokens for a 30-second jump boost.
local players = require("@usbx/players")
local ui = require("@usbx/ui")
local state = require("@usbx/state")
local schema = require("@usbx/schema")
local task = require("@usbx/task")
local tokens = state.create_per_player("tokens", 0, schema.number())
players.joined:connect(function(player)
local hud = ui.mount(player, {
kind = "panel", anchor = "bottom", y = -24,
children = { { kind = "button", id = "boots", text = "Rocket boots: 10 tokens" } },
})
hud.clicked:connect(function(who, id)
if id == "boots" and tokens:get(who) >= 10 then
tokens:increment(who, -10)
local normal = who.jump_height
who.jump_height = 40
hud:set("boots", { text = "Boots on!" })
task.delay(30, function()
who.jump_height = normal
hud:set("boots", { text = "Rocket boots: 10 tokens" })
end)
end
end)
end)Runs 60 second rounds with a 10 second break between them, over and over.
local task = require("@usbx/task")
local ui = require("@usbx/ui")
task.spawn(function()
while true do
ui.announce(nil, { text = "Round starts!" })
ui.countdown(nil, { seconds = 60, label = "Round ends" })
task.sleep(60)
ui.announce(nil, { text = "Round over" })
task.sleep(10)
end
end)The guide greets the player, walks to the castle, and speaks again once it gets there.
local world = require("@usbx/world")
local npc = require("@usbx/npc")
local guide = npc.find("Guide")
guide:say("Follow me!")
guide:move_to(world.find("Castle")):wait()
guide:say("Here we are.")Shows black bars and a 3-second fly-over, then resets the camera.
local players = require("@usbx/players")
local world = require("@usbx/world")
local camera = require("@usbx/camera")
local math3d = require("@usbx/math")
players.joined:connect(function(player)
camera.letterbox(player, { visible = true })
camera.move_to(player, {
position = math3d.vector3.new(0, 40, 60),
look_at = world.find("Castle"),
duration = 3,
}):wait()
camera.letterbox(player, { visible = false })
camera.reset(player, { duration = 1 })
end)Any part tagged "Barrel" blows up as soon as a player touches it.
local world = require("@usbx/world")
local physics = require("@usbx/physics")
world.tagged("Barrel").touched:connect(function(barrel, player)
if player then
physics.explode({ position = barrel.position, radius = 10, force = 500, damage = 30 })
barrel:destroy()
end
end)Wins are kept across every server, and the top 5 get posted in chat.
local data = require("@usbx/data")
local ui = require("@usbx/ui")
local wins = data.ordered("wins")
local function playerWon(player)
wins:increment(player.user_id, 1)
for _, entry in wins:top(5) do
ui.chat(nil, { text = entry.rank .. ". " .. entry.key .. ": " .. entry.value .. " wins" })
end
endA full day passes every 10 minutes.
local world = require("@usbx/world")
world.lighting.cycle_minutes = 10One script fires a Signal and any other script can listen for it.
-- Both scripts define the same Signal by its name.
local signals = require("@usbx/signals")
local schema = require("@usbx/schema")
local scored = signals.define("Scored", schema.struct({ amount = schema.number() }))
-- Script A
scored:fire({ amount = 5 })
-- Script B
scored.received:connect(function(payload)
print("someone scored", payload.amount)
end)