Roblox scripts every game needs, ready to copy and paste
Updated 17 November 2026 · By ClipClip
The short answer
Ten scripts most Roblox games need, ready to paste into Roblox Studio: put each where its label says, change the ID or name in capitals at the top, and press Play. Each one ran in a Studio playtest on 17 November 2026, and they work alone or together: they share one leaderboard, and the saving script keeps all of it.
The 10 scripts
| Script | What it does | Where it goes |
|---|---|---|
| Leaderboard | Shows each player's coins | Script in ServerScriptService |
| Save player data | Keeps everything on the leaderboard between visits | Script in ServerScriptService |
| Kill brick | Kills a player who touches the part | Script inside the part |
| Obby checkpoints | Players respawn at their last stage | Script in ServerScriptService |
| Teleporter | Step on a pad, land somewhere else | Script inside the pad |
| Door with a prompt | Press E or tap to open and close | Script inside the door |
| Game pass item | Gives pass owners a tool | Script in ServerScriptService |
| Game pass button | Sells your pass from a button | LocalScript in a TextButton |
| Developer product | Sells 100 coins, again and again | Script, and a LocalScript button |
| Badge | Awards a badge at the finish | Script inside the part |
How to add a script in Roblox Studio
- In the Explorer (the Window menu, or the Home tab), hover over where the script goes and click the ⊕ button.
- Pick Script, or LocalScript for a button. Delete the
print("Hello world!")line it starts with. - Paste the script, change what's in capitals at the top, and press Play.
A Script runs on Roblox's server and changes the game for everyone. A LocalScript runs on one player's device, for what only they see or press. Errors show in the Output window (the Window menu, or the Script tab), with the script's name and line.
Leaderboard script (leaderstats)
Shows each player's coins at the top right of the screen.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
-- reuses the leaderboard if another script made it
local leaderstats = player:FindFirstChild("leaderstats") or Instance.new("Folder")
leaderstats.Name = "leaderstats" -- this exact name shows it on the leaderboard
leaderstats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
end)To give coins, add to player.leaderstats.Coins.Value from any server script. For another value, like Wins, copy the four coins lines and change the name.
Save player data (DataStore script)
Keeps everything on the leaderboard between visits: coins, the obby stage, any value you add.
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local store = DataStoreService:GetDataStore("PlayerData")
local loaded = {}
local saving = 0 -- saves still running
local function load(player)
player:SetAttribute("Loaded", false) -- the other scripts wait for this
local leaderstats = player:WaitForChild("leaderstats")
local ok, saved
for attempt = 1, 3 do
ok, saved = pcall(store.GetAsync, store, "Player_" .. player.UserId)
if ok then
break
end
task.wait(2)
end
if not ok then
-- never let anyone play, and save, with empty data
warn("Couldn't load " .. player.Name .. ": " .. tostring(saved))
player:Kick("Your data didn't load. Please rejoin.")
return
end
for name, value in saved or {} do
local stat = leaderstats:WaitForChild(name, 5)
if stat then
stat.Value = value
end
end
if player.Parent then
loaded[player] = true
player:SetAttribute("Loaded", true)
end
end
local function save(player)
if not loaded[player] then
return false
end
saving += 1
local data = {}
for _, stat in player.leaderstats:GetChildren() do
if stat:IsA("ValueBase") then
data[stat.Name] = stat.Value
end
end
local ok, err = pcall(store.SetAsync, store, "Player_" .. player.UserId, data)
if not ok then
warn("Couldn't save " .. player.Name .. ": " .. tostring(err))
end
saving -= 1
return ok
end
-- lets other scripts save a player at once, like after a purchase
local savePlayerData = Instance.new("BindableFunction")
savePlayerData.Name = "SavePlayerData"
savePlayerData.OnInvoke = save
savePlayerData.Parent = ServerScriptService
Players.PlayerAdded:Connect(load)
Players.PlayerRemoving:Connect(function(player)
save(player)
loaded[player] = nil
end)
-- when the server closes, save everyone, and wait until every save is done
game:BindToClose(function()
for _, player in Players:GetPlayers() do
task.spawn(save, player)
end
while saving > 0 do
task.wait()
end
end)
-- and every 2 minutes, in case the server crashes
while true do
task.wait(120)
for _, player in Players:GetPlayers() do
task.spawn(save, player)
end
end- Needs a leaderboard: the script above, the checkpoints below, or both.
- To save in Studio, publish the game, then turn on Enable Studio Access to API Services in File, Experience Settings, Security. For a game that's already live, Roblox advises a test copy: Studio uses the real data.
- It never saves over data it couldn't read: it tries 3 times, then asks the player to rejoin. It saves when a player leaves, every 2 minutes, when the server closes, and right after each purchase made with the product script below.
How it works, how to test it, and what to do when data doesn't save: how to save player data with DataStores.
Kill brick script
Kills any player who touches the part: lava, spikes, a laser.
local part = script.Parent
part.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
humanoid.Health = 0
end
end)Turn on the part's Anchored so it doesn't fall. To make more, copy the part: the script copies with it.
Checkpoint script for an obby
Each checkpoint a player reaches raises their Stage on the leaderboard, and they respawn on it.
local Players = game:GetService("Players")
local checkpoints = workspace:WaitForChild("Checkpoints")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats") or Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 1
stage.Parent = leaderstats
-- every spawn starts at the player's last checkpoint
player.CharacterAdded:Connect(function(character)
character:WaitForChild("HumanoidRootPart")
while player.Parent and player:GetAttribute("Loaded") == false do
task.wait() -- a saved stage is still loading
end
task.wait()
local checkpoint = checkpoints:FindFirstChild(tostring(stage.Value))
if checkpoint then
character:PivotTo(checkpoint.CFrame + Vector3.new(0, 3, 0))
end
end)
end)
for _, checkpoint in checkpoints:GetChildren() do
checkpoint.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
local stage = player and player.leaderstats:FindFirstChild("Stage")
-- only the next checkpoint counts, so no one skips a stage
if stage and tonumber(checkpoint.Name) == stage.Value + 1 then
stage.Value += 1
end
end)
end- In Workspace, add a folder named Checkpoints.
- Inside it, put anchored parts named 1, 2, 3 in order, with 1 at the start.
Only the next checkpoint counts, so nobody skips a stage. With the saving script, the stage is kept too, and players start their next visit on it.
Teleport script: a pad that moves players
Step on the pad, land on another part, anywhere in your game.
local pad = script.Parent
local destination = workspace:WaitForChild("Destination")
pad.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local last = character:GetAttribute("LastTeleport") or 0
-- a 2-second wait, so a pad at the other end doesn't send you straight back
if humanoid and os.clock() - last > 2 then
character:SetAttribute("LastTeleport", os.clock())
character:PivotTo(destination.CFrame + Vector3.new(0, 4, 0))
end
end)Name the part players arrive on Destination. For a way back, put the same script in that part and change "Destination" to the first pad's name: the 2-second wait stops them from bouncing between the two.
Door you open with a prompt (press E)
A sliding door with a prompt: E on a computer, a tap on a phone, a button on a controller.
local TweenService = game:GetService("TweenService")
local door = script.Parent
local closed = door.CFrame
local opened = door.CFrame * CFrame.new(door.Size.X, 0, 0) -- slides sideways by its width
local prompt = Instance.new("ProximityPrompt")
prompt.ActionText = "Open"
prompt.ObjectText = "Door"
prompt.Parent = door
local isOpen = false
prompt.Triggered:Connect(function()
isOpen = not isOpen
TweenService:Create(door, TweenInfo.new(0.6), { CFrame = isOpen and opened or closed }):Play()
prompt.ActionText = isOpen and "Close" or "Open"
end)Turn on the door's Anchored. It slides sideways by its own width; to slide it up instead, change CFrame.new(door.Size.X, 0, 0) to CFrame.new(0, door.Size.Y, 0).
Game pass script: give an item
Gives everyone who owns your pass a tool, after every respawn, and right away when they buy it in the game.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local PASS_ID = 0 -- your pass's ID
local TOOL_NAME = "Sword" -- the tool's name in ServerStorage
local function giveTool(player)
local tool = ServerStorage:FindFirstChild(TOOL_NAME)
local starterGear = player:WaitForChild("StarterGear")
if tool and not starterGear:FindFirstChild(TOOL_NAME) then
tool:Clone().Parent = starterGear -- keeps it after every respawn
if player.Character then
tool:Clone().Parent = player.Backpack -- and gives it now
end
end
end
Players.PlayerAdded:Connect(function(player)
local ok, ownsPass = pcall(MarketplaceService.UserOwnsGamePassAsync, MarketplaceService, player.UserId, PASS_ID)
if ok and ownsPass then
giveTool(player)
end
end)
-- bought during the game
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, passId, purchased)
if purchased and passId == PASS_ID then
giveTool(player)
end
end)- Create the pass in the Creator Hub, under your game's Monetization, Passes. Its ⋯ menu has Copy Asset ID: paste it as
PASS_ID. - Put the tool in ServerStorage, named like
TOOL_NAME.
Every step of making and selling the pass: how to make a game pass.
Developer product script: sell coins
Sells 100 coins that players can buy again and again. It needs the leaderboard script.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local PRODUCT_ID = 0 -- your developer product's ID
local COINS = 100
MarketplaceService:BindReceiptHandler(Enum.ReceiptType.DeveloperProduct, function(receipt)
local player = Players:GetPlayerByUserId(receipt.PlayerId)
while player and player.Parent and player:GetAttribute("Loaded") == false do
task.wait() -- their saved coins are still loading
end
local leaderstats = player and player.Parent and player:FindFirstChild("leaderstats")
local coins = leaderstats and leaderstats:FindFirstChild("Coins")
if not coins then
return Enum.ReceiptDecision.NotProcessedYet -- given when they come back
end
coins.Value += COINS
-- with the saving script, save before telling Roblox the purchase is done
local savePlayerData = ServerScriptService:FindFirstChild("SavePlayerData")
if savePlayerData and not savePlayerData:Invoke(player) then
coins.Value -= COINS -- not saved: Roblox delivers the purchase again later
return Enum.ReceiptDecision.NotProcessedYet
end
return Enum.ReceiptDecision.Processed
end, { PRODUCT_ID })local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local PRODUCT_ID = 0 -- your developer product's ID
script.Parent.Activated:Connect(function()
MarketplaceService:PromptProductPurchase(Players.LocalPlayer, PRODUCT_ID)
end)- Create the product under your game's Monetization, Developer Products, and paste its ID in both scripts.
- It uses
BindReceiptHandler, Roblox's newer way to handle receipts. For a second product, copy the handler with the new ID. - With the saving script, it waits for a player's saved coins before adding, so a purchase made from your game page's Store tab, given when they join, isn't lost.
- It also saves the coins before telling Roblox the purchase is done. If that save fails, it takes them back, and Roblox delivers the purchase again later.
Badge script: award a badge
Awards a badge when a player touches the part: put it on your obby's finish.
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BADGE_ID = 0 -- your badge's ID
local part = script.Parent
local awarded = {}
part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and not awarded[player] then
awarded[player] = true
local ok, err = pcall(BadgeService.AwardBadgeAsync, BadgeService, player.UserId, BADGE_ID)
if not ok then
warn("Couldn't award the badge: " .. tostring(err))
awarded[player] = nil -- tries again on the next touch
end
end
end)
Players.PlayerRemoving:Connect(function(player)
awarded[player] = nil
end)Create the badge in the Creator Hub, under your game's Engagement, Badges: up to 5 a day are free, then 100 Robux each. It uses AwardBadgeAsync, which replaced AwardBadge.
How we tested them
On 17 November 2026, we pasted all ten unchanged into a published test game, with a real test pass, product and badge, and played it in Roblox Studio:
- Coins and Stage shared one leaderboard, and both came back after stopping and restarting the game.
- Checkpoint 3 didn't count from stage 1. After 2 and 3, the kill brick killed the player, who respawned on 3.
- The teleporter worked both ways without bouncing, and the door opened and closed with E.
- Test purchases, free in Studio, added 100 coins each, already in the data store a second after we clicked Buy. When we made the save fail on purpose, the coins were taken back, and Roblox delivered that purchase again with the next one. In a simulated slow load, a purchase waited for the saved coins and was added on top.
- The badge was awarded, and the pass owner had the sword on joining and after every respawn.
Not tested: buying the pass in the game, since the account that makes a pass already owns it.
When a script doesn't work
- Read the Output window. The red line names the script and the line that broke.
- Check where it is. A Script inside StarterGui or a LocalScript in ServerScriptService doesn't run.
- Check the names.
Checkpoints,Destinationandleaderstatsmust match exactly, capitals included. - Check the IDs. A pass, product or badge ID left at 0 does nothing.
Stuck? Paste the script and the red line into Roblox Studio's Assistant and ask why: how to make a Roblox game with AI.
Questions
Where do I put scripts in Roblox Studio?
In the Explorer, hover over where the script goes, click the ⊕ button and pick Script or LocalScript. Game rules go in ServerScriptService, a part's own script inside the part, and a button's LocalScript inside the button.
What's the difference between a Script and a LocalScript?
A Script runs on Roblox's server and changes the game for everyone: coins, doors, purchases. A LocalScript runs on one player's device, for what only they see or press, like a button.
Why isn't my LocalScript running?
It's probably somewhere LocalScripts don't run, like ServerScriptService or a part in Workspace. Put it in StarterGui, StarterPlayerScripts, StarterCharacterScripts or a tool.
What language do Roblox scripts use?
Luau, Roblox's scripting language, made from Lua 5.1 with types added. If you know Lua, you can read it.
How do I save player data on Roblox?
With a data store: the saving script on this page loads each player's leaderboard when they join and saves it when they leave, every 2 minutes and when the server closes. In Studio, turn on Enable Studio Access to API Services first.
Why doesn't my data save in Roblox Studio?
Studio can't reach data stores until the game is published and Enable Studio Access to API Services is on, in File, Experience Settings, Security. Roblox advises doing it on a test copy of a live game, since Studio uses the real data.
How do I make a kill brick in Roblox Studio?
Insert a part, anchor it, and put a Script inside it that sets the Health of whatever Humanoid touches it to 0. Copy the part to make more: the script copies with it.
How do I make a game pass give an item?
Put the tool in ServerStorage and use the game pass item script: it checks UserOwnsGamePassAsync when a player joins and copies the tool into their StarterGear, so they keep it after every respawn.
Why doesn't my game pass button do anything?
If your account made the pass, it already owns it, so Roblox shows you no purchase window. Test it from a second account, and check that the ID in the script is the pass's.
How do I make a developer product in Roblox?
Create it in the Creator Hub under your game's Monetization, Developer Products, copy its ID, and give the item in a server script that handles its receipt. Roblox says to give items there, not in PromptProductPurchaseFinished.
Is it safe to use free scripts from the Toolbox?
Not always: free models can hide scripts that let someone else control your game. Read every script in a model before you keep it, and delete any you don't understand.
Can AI write Roblox scripts for me?
Yes: Assistant in Roblox Studio writes and runs Luau, and Claude Code or Cursor can work in Studio through its MCP server. Test after every change: AI code has bugs too.
Can I use these scripts in my game?
Yes, in any game, free, with no credit needed.
Sources
- Roblox Creator Hub, Data stores, read 17 November 2026
- Roblox Creator Hub, Passes, read 17 November 2026
- Roblox Creator Hub, Developer products, read 17 November 2026
- Roblox Creator Hub, MarketplaceService, read 17 November 2026
- Roblox Creator Hub, Badges, read 17 November 2026
- Roblox Creator Hub, BadgeService, read 17 November 2026
- Roblox Creator Hub, ProximityPrompt, read 17 November 2026
- Roblox Creator Hub, Data model (where scripts run), read 17 November 2026
- Roblox Creator Hub, Luau, read 17 November 2026