1. Kill brick: How do you defeat a player on touch?
A kill brick is a Part that listens for contact, finds the touching character’s Humanoid, and sets its Health to zero. It is a useful Roblox Studio script for beginners because one short example teaches variables, functions, events, object lookup, and a visible result: the player respawns after touching the hazard.
Insert a Part, anchor it, and add a regular Script inside it. Roblox Creator Hub’s Deadly Lava tutorial uses the same Touched event and Humanoid.Health = 0 pattern. Replace the Script’s contents with this code:
local brick = script.Parent
local function onTouched(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
brick.Touched:Connect(onTouched)
Test it by pressing Play and walking onto the brick. Because NPC models can also contain Humanoids, this version will defeat them too.
What are scripts, and how does Roblox Studio use Luau?
Scripts are text files that give objects and systems custom behavior, while Luau is the programming language used to write that behavior. Roblox Creator Hub describes Luau as a language derived from Lua 5.1 and notes that Studio’s editor provides autocompletion, syntax highlighting, linting, and type checking in its Luau documentation.
A server Script is appropriate for shared gameplay rules such as hazards, coins, doors, and checkpoints. A LocalScript runs for one player and suits interfaces, camera effects, and local input; Roblox’s script-location documentation explains that location and run context determine where code executes. If you are still learning Studio’s Explorer and object hierarchy, start with How to Add Models in Roblox Studio before tackling larger systems. These examples use small, independent objects so you can understand each result before combining them into a game.
2. Disappearing platform: How do you make a platform vanish and return?
A disappearing platform changes its Transparency to 1 and its CanCollide property to false, waits, and then restores both properties. This teaches property changes, delays, state, and a debounce—a Boolean value that prevents the same touch event from starting the sequence several times at once.
Create an anchored Part and place a Script inside it. Roblox Creator Hub confirms that Transparency ranges from 0 for visible to 1 for invisible, while CanCollide controls whether other parts can pass through, in its introductory scripting tutorial. Use this code:
local platform = script.Parent
local busy = false
local function disappear()
if busy then
return
end
busy = true
platform.Transparency = 1
platform.CanCollide = false
task.wait(3)
platform.Transparency = 0
platform.CanCollide = true
busy = false
end
platform.Touched:Connect(disappear)
The busy check matters because Roblox documents that physical contact can fire Touched repeatedly as parts move or settle. Change the three-second delay only after the basic version behaves reliably.
3. Coin collection: How do you award a coin when a player touches an object?
A coin-collection script identifies the player whose character touched a coin, increases that player’s Coins value, and disables the coin so it cannot award points twice. It introduces services, player lookup, value changes, and the connection between a world object and player-specific data.
Create a small anchored Part named Coin, set CanCollide to false, and add a Script. This example expects the leaderstats setup in item 4, so add both scripts before testing. Roblox Creator Hub uses Players:GetPlayerFromCharacter() in its official coin-collection tutorial to match a touched character to its Player.
local Players = game:GetService("Players")
local coin = script.Parent
local collected = false
local function collect(otherPart)
if collected then
return
end
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if not player then
return
end
local leaderstats = player:FindFirstChild("leaderstats")
local coins = leaderstats and leaderstats:FindFirstChild("Coins")
if not coins then
return
end
collected = true
coins.Value += 1
coin.CanTouch = false
coin.Transparency = 1
task.wait(0.2)
coin:Destroy()
end
coin.Touched:Connect(collect)
Destroying the coin makes this a one-use pickup. For a reusable collectible, hide it, wait, and restore its transparency and CanTouch property instead.
4. Leaderboard and currency: How do you display a player’s coins?
Roblox displays a built-in player-list statistic when the player contains a Folder named exactly leaderstats with value objects inside it. A server script can create that folder and an IntValue named Coins whenever a player joins, giving the coin script a reliable place to store its total.
Add a Script to ServerScriptService, not to a coin or GUI. Roblox Creator Hub states in its leaderboards documentation that the folder name must be lowercase leaderstats; another name will not activate the built-in display. Paste this code:
local Players = game:GetService("Players")
local function setupLeaderboard(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
end
Players.PlayerAdded:Connect(setupLeaderboard)
This value lasts only for the current server session. Persistent currency requires a server-side data store, error handling, and careful save design, so learn that separately after these fundamentals.
5. GUI button: How do you make an on-screen button respond?
A simple GUI button uses a LocalScript to connect the button’s Activated event to a function. This teaches client-side code and input without requiring separate mouse and touch handlers, because Roblox documents Activated as the cross-platform event for pressing or tapping a TextButton or ImageButton.
Under StarterGui, create a ScreenGui, then add a TextButton inside it. Put a LocalScript inside the button and use the following code to toggle its label. Roblox Creator Hub’s button guide also uses a LocalScript parented to the button.
local button = script.Parent
local enabled = false
local function onActivated()
enabled = not enabled
button.Text = enabled and "Light: On" or "Light: Off"
end
button.Activated:Connect(onActivated)
This only changes the local interface; it does not alter a shared game object. Actions that affect currency, damage, or shared objects should be validated by server code rather than trusted solely to a LocalScript.
6. Proximity prompt: How do you let players interact with a nearby door?
A ProximityPrompt provides a built-in interaction prompt when a player approaches an object, and its Triggered event reports which player used it. Connecting that event to a server Script can open or close a simple door while teaching event parameters, Boolean state, and object relationships.
Create an anchored Part named Door, insert a ProximityPrompt into it, and insert a Script inside the prompt. Set the prompt’s ActionText to “Open” and ObjectText to “Door” in Properties. Roblox Creator Hub says prompt events may be connected through the prompt itself or centrally through ProximityPromptService in its proximity prompt documentation.
local prompt = script.Parent
local door = prompt.Parent
local open = false
local function toggleDoor()
open = not open
door.CanCollide = not open
door.Transparency = open and 0.7 or 0
prompt.ActionText = open and "Close" or "Open"
end
prompt.Triggered:Connect(toggleDoor)
This is suitable for a practice door, but valuable rewards or purchases need additional server-side checks. Roblox’s security documentation warns that client-visible prompt settings can be manipulated, so proximity alone must not authorize sensitive actions.
7. Checkpoint and respawn: How do you save the latest checkpoint?
A checkpoint can set Player.RespawnLocation to the SpawnLocation the player most recently touched. This creates an obby-style respawn system without manually moving newly spawned characters, and it reinforces player lookup, type checking, and the difference between an ordinary Part and a specialized Roblox object.
Insert a SpawnLocation for each checkpoint and put this Script inside every one. Roblox Creator Hub specifically recommends Player.RespawnLocation for progression systems with checkpoints in its spawn and respawn guide. Use the same code in each checkpoint:
local Players = game:GetService("Players")
local checkpoint = script.Parent
local function onTouched(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player and player.RespawnLocation ~= checkpoint then
player.RespawnLocation = checkpoint
end
end
checkpoint.Touched:Connect(onTouched)
Confirm that checkpoint is a SpawnLocation, because RespawnLocation cannot point to a normal Part. This example remembers progress only while the player remains in that server; cross-session checkpoint saving requires a data store.
How should you test these scripts and decide what to learn next?
Test one script at a time in a simple place, watch Studio’s Output window for errors, and confirm the result on both the client and server. After all seven work separately, combine two systems—such as coins and the leaderboard—before attempting a larger game.
Roblox Creator Hub explains that Studio’s Test mode runs separate client and server simulations and lets you toggle between them in its testing modes guide. Use Play or F5 when a character is required, use Stop or Shift+F5 when finished, and never judge a touch script with Run mode because Run does not insert an avatar. Test GUI buttons with mouse and touch emulation, and use Server & Clients when checking behavior involving more than one player.
The next useful Luau topics are conditionals, loops, tables, ModuleScripts, remote events, and data stores. Keep authoritative decisions—awarding money, dealing damage, or unlocking purchases—on the server, and treat client input as a request that must be checked. For more beginner Roblox game development resources, browse the Roblox Game & Studio Guides or return to A Lovely Light.
FAQ:
- What scripting language does Roblox Studio use? → Roblox Studio uses Luau, a language derived from Lua 5.1. Studio includes autocompletion, syntax highlighting, linting, and type checking for Luau code.
- Should a beginner use a Script or a LocalScript? → Use a server Script for shared gameplay rules such as hazards, currency, doors, and checkpoints. Use a LocalScript for one player’s interface, camera, or local input.
- Why is my Roblox script not running? → Check the Output window for errors and confirm that the script is in a location where its type can run. Also use Play mode when the code requires a player character.
- Do leaderstats save when a player leaves? → No. A basic leaderstats value lasts only for the current server session; persistent progress requires a server-side data store.