All topics and tagsAbout

Dead Rails screenshot of a black steam locomotive pulling an armoured wagon across a desert plain

Roblox Studio Scripts: 13 Free Copy-Paste Luau Scripts Checked Against the Docs

Free copy-paste Luau scripts for Roblox Studio: kill brick, leaderstats, coins, saving, doors, teleports, game passes and more, each checked against the docs.

Image: Dead Rails by RCM Games (Roblox)

On this page16
  1. How to use these scripts
  2. 1. Kill brick
  3. 2. Leaderstats with Coins
  4. 3. Touch-to-collect coin
  5. 4. Save and load Coins with DataStoreService
  6. 5. Teleport pad
  7. 6. Clickable part (ClickDetector)
  8. 7. Speed and jump pad
  9. 8. Day and night cycle
  10. 9. Door that opens with TweenService
  11. 10. Proximity prompt
  12. 11. Game pass check
  13. 12. RemoteEvent button (LocalScript and Script)
  14. 13. Obby checkpoint (SpawnLocation)
  15. Where to go next
  16. Roblox Studio Scripts FAQ

Pick a script below, create the right object in the Explorer (a Script or a LocalScript, in the place each section names), paste the code, and press Play to try it. Every script here uses only APIs we found in the official Roblox Creator Docs, and each section links the page we checked it against. Several are lifted almost line for line from Roblox’s own tutorials. We have checked the code against the docs; we have not run every one in Studio ourselves, so test each one in your own place before you build on it.

Quick facts

Scripts
13, all Luau
Cost
Free to copy and change
Checked against
create.roblox.com/docs and github.com/Roblox/creator-docs
Test with
Test (F5), stop with Shift+F5

How to use these scripts

A Script runs on the server. A new Script runs in server containers such as ServerScriptService or the Workspace, which includes placing it inside a part. A LocalScript runs on one player’s device and belongs in StarterPlayerScripts, StarterCharacterScripts, StarterGui or StarterPack, according to the script locations doc.

To add one, hover over the parent in the Explorer, click the plus button, and choose Script or LocalScript. Delete the starter print("Hello world!") line and paste the code.

To test, pick a mode from the dropdown next to the Play button in the toolbar and click Play. Test (F5) puts your avatar in the game, Run (F8) runs the simulation without one, and Shift+F5 stops (testing modes). Keep the Output window open, because that is where print and warn messages and errors show up.

The Roblox Studio toolbar with the playtest controls
Image: © Roblox Corporation, from the Roblox Creator Docs

If you are new to Luau, read how to script in Roblox first. It explains functions, events and RemoteEvents, which every script below leans on.

1. Kill brick

Resets any player who touches the part. This is the official deadly lava code.

Where: a Script inside the part (for example a part named LavaFloor).

local lava = script.Parent

local function kill(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end

lava.Touched:Connect(kill)

Test: press F5 and walk onto the part. Your character should fall apart and respawn. Source: Deadly lava tutorial.

2. Leaderstats with Coins

Adds a Coins counter to the player list for everyone who joins. A Folder named exactly leaderstats inside the Player is what makes Roblox show it.

Where: a Script in ServerScriptService. Name it Leaderstats.

local Players = game:GetService("Players")

local function onPlayerAdded(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(onPlayerAdded)

Test: press F5 and look at the top right of the screen. Your name should show with Coins 0. Source: Score points tutorial, which uses the same code with a value named Points.

3. Touch-to-collect coin

Gives the player 1 coin and removes the coin part. It needs script 2 running so the Coins value exists.

Where: a Script inside the coin part. Set the part’s Anchored and CanCollide as you like (Anchored keeps it floating).

local Players = game:GetService("Players")
local coin = script.Parent
local collected = false

local function onTouched(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 coins then
		collected = true
		coins.Value += 1
		coin:Destroy()
	end
end

coin.Touched:Connect(onTouched)

The collected flag stops one touch from counting several times, since Touched can fire for each body part. Test: press F5, walk into the coin, and watch Coins go to 1. Sources: Players:GetPlayerFromCharacter and BasePart.Touched.

4. Save and load Coins with DataStoreService

Loads a player’s Coins when they join and saves them when they leave. Both calls go over the network and can fail, so each sits in pcall(), as the docs advise.

Where: a Script in ServerScriptService. Use it instead of script 2, since it creates the leaderstats too.

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local coinStore = DataStoreService:GetDataStore("PlayerCoins")

local function onPlayerAdded(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

	local success, saved = pcall(function()
		return coinStore:GetAsync(tostring(player.UserId))
	end)
	if success and saved then
		coins.Value = saved
	elseif not success then
		warn("Could not load coins for " .. player.Name)
	end
end

local function onPlayerRemoving(player)
	local coins = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Coins")
	if not coins then
		return
	end
	local success, err = pcall(function()
		coinStore:SetAsync(tostring(player.UserId), coins.Value)
	end)
	if not success then
		warn("Could not save coins: " .. tostring(err))
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)

Test: press F5, collect a coin, stop, press F5 again. Coins should still read 1. Sources: Data stores and Players.PlayerRemoving. For a game with lots of saved stats, follow the official save player data tutorial, which handles more edge cases than this short version.

5. Teleport pad

Moves a player who steps on one part to another part. PivotTo is the function the docs name for moving models such as a character.

Where: a Script inside the pad part. Add a second part named TeleportTarget directly in the Workspace.

local Players = game:GetService("Players")
local pad = script.Parent
local target = workspace:WaitForChild("TeleportTarget")

local function onTouched(otherPart)
	local character = otherPart.Parent
	local player = Players:GetPlayerFromCharacter(character)
	if player then
		character:PivotTo(target.CFrame + Vector3.new(0, 5, 0))
	end
end

pad.Touched:Connect(onTouched)

The 5 stud lift drops the player on top of the target instead of inside it. Test: press F5 and step on the pad. Source: PVInstance:PivotTo.

6. Clickable part (ClickDetector)

Changes the part to a random color when a player clicks or taps it, and prints who clicked.

Where: insert a ClickDetector into the part, then a Script into the same part.

local part = script.Parent
local clickDetector = part:WaitForChild("ClickDetector")

local function onClicked(playerWhoClicked)
	part.Color = Color3.new(math.random(), math.random(), math.random())
	print(playerWhoClicked.Name .. " clicked the part")
end

clickDetector.MouseClick:Connect(onClicked)

MouseClick fires for a mouse click, a tap on touch devices, and the A button on gamepads, as long as the character is within the detector’s MaxActivationDistance. Test: press F5, walk close and click the part. Source: ClickDetector.

The Output window in Roblox Studio showing printed messages from scripts
Image: © Roblox Corporation, from the Roblox Creator Docs

7. Speed and jump pad

Gives a player more speed and a higher jump while they stand on the pad’s effect. Default WalkSpeed is 16 studs per second.

Where: a Script inside the pad part.

local pad = script.Parent

local function onTouched(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = 32
		humanoid.UseJumpPower = true
		humanoid.JumpPower = 80
	end
end

pad.Touched:Connect(onTouched)

The boost lasts until the character respawns. UseJumpPower set to true tells the Humanoid to use JumpPower instead of JumpHeight. Test: press F5, touch the pad, then run and jump. Sources: Humanoid.WalkSpeed, Humanoid.UseJumpPower and Humanoid.JumpPower.

8. Day and night cycle

Moves the sun and moon by advancing Lighting.ClockTime, which is the time of day in hours. The docs note ClockTime does not change during gameplay unless a script changes it.

Where: a Script in ServerScriptService.

local Lighting = game:GetService("Lighting")

local HOURS_PER_SECOND = 0.1 -- one full day every 240 seconds

while true do
	local dt = task.wait(1)
	Lighting.ClockTime = (Lighting.ClockTime + HOURS_PER_SECOND * dt) % 24
end

Test: press F5 (or Run with F8) and watch the sky. Raise HOURS_PER_SECOND to see it move faster. Source: Lighting.ClockTime. Our lighting guide covers the other Lighting properties.

A Roblox scene lit at night with the Lighting time of day set to midnight
Image: © Roblox Corporation, from the Roblox Creator Docs

9. Door that opens with TweenService

Slides a door up smoothly when a player clicks it, then closes it after 3 seconds.

Where: an anchored door part with a ClickDetector inside it, then a Script in the same part.

local TweenService = game:GetService("TweenService")
local door = script.Parent
local clickDetector = door:WaitForChild("ClickDetector")

local closedCFrame = door.CFrame
local openCFrame = closedCFrame + Vector3.new(0, door.Size.Y, 0)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local isOpen = false

local function onClicked()
	if isOpen then
		return
	end
	isOpen = true
	local openTween = TweenService:Create(door, tweenInfo, { CFrame = openCFrame })
	openTween:Play()
	openTween.Completed:Wait()
	task.wait(3)
	local closeTween = TweenService:Create(door, tweenInfo, { CFrame = closedCFrame })
	closeTween:Play()
	closeTween.Completed:Wait()
	isOpen = false
end

clickDetector.MouseClick:Connect(onClicked)

The door must be Anchored, or physics will fight the tween. Test: press F5 and click the door. Sources: TweenService:Create, TweenInfo and Tween.Completed.

10. Proximity prompt

Shows a “press E” style prompt when a player walks close, and runs code when they trigger it. Here it heals the player to full.

Where: insert a ProximityPrompt into a part, then a Script in the same part.

local part = script.Parent
local prompt = part:WaitForChild("ProximityPrompt")
prompt.ActionText = "Heal"
prompt.ObjectText = "Health Station"

local function onTriggered(playerWhoTriggered)
	local character = playerWhoTriggered.Character
	local humanoid = character and character:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.Health = humanoid.MaxHealth
	end
end

prompt.Triggered:Connect(onTriggered)

Test: press F5, walk up to the part and press the key shown (E on keyboard by default). Source: ProximityPrompt and the proximity prompts guide.

11. Game pass check

Checks on join whether a player owns a game pass, inside pcall so a failed web call does not break the script. This is the official sample with the speed reward filled in.

Where: a Script in ServerScriptService. Replace the ID with your pass ID from the Creator Dashboard.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local passID = 0000000 -- your pass ID

local function onPlayerAdded(player)
	local hasPass = false

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, passID)
	end)

	if not success then
		warn("Error while checking if player has pass: " .. tostring(message))
		return
	end

	if hasPass then
		print(player.Name .. " owns the pass")
		player.CharacterAdded:Connect(function(character)
			character:WaitForChild("Humanoid").WalkSpeed = 24
		end)
		if player.Character then
			player.Character:WaitForChild("Humanoid").WalkSpeed = 24
		end
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

Test: publish the game, then press F5 on an account that owns the pass and check the Output. The docs also note that during a pass free trial, UserOwnsGamePassAsync returns true, so use GetPassOwnershipAsync for permanent grants. Source: Passes.

12. RemoteEvent button (LocalScript and Script)

A UI button on the player’s screen asks the server for a coin. The server decides, because anything a client sends cannot be trusted. It needs script 2 or 4 running.

Setup: add a RemoteEvent to ReplicatedStorage named RequestCoin. In StarterGui, add a ScreenGui with a TextButton inside it.

LocalScript, inside the TextButton:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local requestCoin = ReplicatedStorage:WaitForChild("RequestCoin")
local button = script.Parent

button.Activated:Connect(function()
	requestCoin:FireServer()
end)

Script, in ServerScriptService:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local requestCoin = ReplicatedStorage:WaitForChild("RequestCoin")

local COOLDOWN = 5
local lastRequest = {}

requestCoin.OnServerEvent:Connect(function(player)
	local now = os.clock()
	if lastRequest[player] and now - lastRequest[player] < COOLDOWN then
		return
	end
	lastRequest[player] = now

	local coins = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Coins")
	if coins then
		coins.Value += 1
	end
end)

The first parameter of OnServerEvent is always the Player who fired it; Roblox adds it, the client cannot fake it. The 5 second cooldown on the server is the check that stops a cheater from spamming the event. Test: press F5 and click the button. The Output labels messages as client or server, which helps here. Sources: Remote events and callbacks and GuiButton.Activated.

Roblox Studio Output window with messages labeled as coming from the client or the server
Image: © Roblox Corporation, from the Roblox Creator Docs

13. Obby checkpoint (SpawnLocation)

Makes a player respawn at the last checkpoint they touched. The docs say Player.RespawnLocation sends a player back to a given SpawnLocation, which must be in the Workspace and either Neutral or on the player’s team.

Where: put SpawnLocation parts in the Workspace along your course, each with Neutral checked, and group them in a Folder named Checkpoints. Then add a Script in ServerScriptService.

local Players = game:GetService("Players")
local checkpoints = workspace:WaitForChild("Checkpoints")

local function onCheckpointTouched(checkpoint, otherPart)
	local player = Players:GetPlayerFromCharacter(otherPart.Parent)
	if player and player.RespawnLocation ~= checkpoint then
		player.RespawnLocation = checkpoint
		print(player.Name .. " reached " .. checkpoint.Name)
	end
end

for _, checkpoint in checkpoints:GetChildren() do
	if checkpoint:IsA("SpawnLocation") then
		checkpoint.Touched:Connect(function(otherPart)
			onCheckpointTouched(checkpoint, otherPart)
		end)
	end
end

Pair it with the kill brick from script 1 and you have the core of an obby. Test: press F5, touch a checkpoint, then step on a kill brick. You should respawn at the checkpoint. Sources: Player.RespawnLocation and SpawnLocation, which also describes a team-based checkpoint method using AllowTeamChangeOnTouch.

Where to go next

Theme Park Tycoon 2 key art of a full roller coaster train with a swing ride and coaster hills behind
Example: Theme Park Tycoon 2, a game where the rides, queues and money all run on scripts. Image: Theme Park Tycoon 2 by Den_S (Roblox)

These scripts cover most of what a first game needs. The obby guide puts scripts 1 and 13 to work, and the tycoon guide builds on leaderstats, saving and RemoteEvents.

If you would rather describe a script than paste one, an AI tool can write variations of anything here. The AI script generator guide covers prompting and reviewing the output, and the Roblox Studio MCP guide shows how to let Claude or Cursor create scripts inside Studio directly. Either way, compare what you get against the doc pages linked above, the same way we checked this list.

Roblox Studio Scripts FAQ

Where do I paste a script in Roblox Studio?

Server Scripts go in ServerScriptService or inside a part in the Workspace. LocalScripts go in StarterPlayerScripts, StarterCharacterScripts, StarterGui or StarterPack. Each script on this page says where it belongs.

Are these Roblox scripts free to use?

Yes. They are short examples built from the APIs and code samples in the Roblox Creator Docs. Paste them into your own game and change them however you like.

Why does my DataStore script not work in Studio?

Studio cannot reach data stores by default. Publish the game, then turn on Enable Studio Access to API Services under File › Experience Settings › Security and click Save, ideally on a test copy.

What is the difference between a Script and a LocalScript?

A Script runs on the server and changes things every player sees. A LocalScript runs on one player's device, which is right for buttons and UI. They talk through a RemoteEvent. See how to script in Roblox.

Can AI write these scripts for me?

It can, and Roblox Assistant or Claude through the Studio MCP server will write similar code. Read every line it gives you. Our AI script generator guide covers how to check the output.