Lesson 3
Checkpoints
Goal: Move a player's respawn point as they progress.
about 7 min3 practice exercises
Without checkpoints, one mistake sends a player back to the very start, which is a common reason to quit. A checkpoint moves their respawn point forward.
Each checkpoint is a SpawnLocation. Put them in a folder in Workspace called Checkpoints, name the first one Start, and leave Neutral ticked on all of them so any player can use them.
A player has a RespawnLocation property. Set it to a SpawnLocation and that is where they come back. One script in ServerScriptService handles every checkpoint:
local Players = game:GetService("Players")
local checkpoints = workspace:WaitForChild("Checkpoints")
Players.PlayerAdded:Connect(function(player)
player.RespawnLocation = checkpoints:WaitForChild("Start")
end)
for _, checkpoint in checkpoints:GetChildren() do
checkpoint.Touched:Connect(function(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
player.RespawnLocation = checkpoint
end
end)
end
New players start at Start. After that, the last checkpoint they touched is where they respawn.
One script for all checkpoints is better than a copy inside each one. When you want to change how checkpoints work, you change it once.
Try it in Studio
Optional, and the best way to make it stick.
Add three SpawnLocations in a Checkpoints folder, add the script, then reset your character after each one.
Sources
Checked against Roblox's documentation on . The lesson is in our own words; these pages are the source of truth.