RB-004
Roblox checkpoint system script
Players respawn at the last checkpoint part they touched, with a Stage counter.
- Script type
- Script
- Where it goes
- ServerScriptService
- Category
- Game flow
For your own game in Roblox Studio. Not for use in other people's games.
The code
-- Checkpoint system for an obby.
-- Put your checkpoint Parts in a Folder in the Workspace named "Checkpoints".
-- Name them 1, 2, 3 ... in the order players reach them.
local FOLDER_NAME = "Checkpoints"
local SPAWN_HEIGHT = 4 -- studs above the checkpoint to place the player
local Players = game:GetService("Players")
local folder = workspace:WaitForChild(FOLDER_NAME)
local function getStage(player)
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
end
local stage = leaderstats:FindFirstChild("Stage")
if not stage then
stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 0
stage.Parent = leaderstats
end
return stage
end
local function onPlayerAdded(player)
local stage = getStage(player)
player.CharacterAdded:Connect(function(character)
if stage.Value == 0 then
return -- no checkpoint reached yet; use the normal spawn
end
local checkpoint = folder:FindFirstChild(tostring(stage.Value))
local root = character:WaitForChild("HumanoidRootPart", 5)
if checkpoint and root then
character:PivotTo(checkpoint.CFrame + Vector3.new(0, checkpoint.Size.Y / 2 + SPAWN_HEIGHT, 0))
end
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAdded, player)
end
-- Set up each checkpoint.
for _, checkpoint in folder:GetChildren() do
local number = tonumber(checkpoint.Name)
if number and checkpoint:IsA("BasePart") then
checkpoint.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player then
return
end
local stage = getStage(player)
if number > stage.Value then
stage.Value = number
end
end)
end
endHow to set it up
- In the Workspace, add a Folder and name it Checkpoints.
- Put your checkpoint Parts inside the folder. Rename them 1, 2, 3 and so on. Set Anchored to true.
- Add the Script to ServerScriptService.
- Play. Touch checkpoint 2, then reset your character. You should come back at checkpoint 2.
Change it
- Players can only go up. Touching checkpoint 1 after checkpoint 3 does nothing.
- The script adds a Stage number to the leaderboard. It shares the leaderstats folder with a Coins script without a clash.
- Stage is not saved between visits. Add it to the Save data script if you want that.
- Checkpoint names must be plain numbers. A name like Checkpoint1 is skipped.
More in Game flow
More Roblox tools
- Shirt and pants templatesFree Roblox clothing templates to download: hoodies, jerseys, jeans, joggers and more.
- Robux tax calculatorWork out what you receive after the marketplace fee, or what to charge.
- Robux to USD calculatorConvert earned Robux to dollars at a DevEx rate you can edit.
- Shirt and pants template makerColour each panel of the 585×559 clothing template and download it.
- Username generatorGenerate usernames that fit the 3–20 character rule.