
Checkpoints
Models · by Brixborg
Green pads that save your place: knocked out, you come back at the last one you touched, and the leaderboard shows your stage. Copy a pad and number it on for more.
Use it in your games: in the studio, open View > Archive, go to the Models shelf and pick "Checkpoints".
The script
-- CHECKPOINTS (a Script inside the Checkpoints model)
-- Touching a green pad saves your place. When you are knocked out you
-- come back at the last pad you touched, and the leaderboard shows which
-- stage you have reached. The pads are the parts in this model called
-- Checkpoint1, Checkpoint2... (add more, numbered on).
local pads = script.Parent
-- Give a new player their leaderboard entry, starting at stage 0.
local function setUp(player)
local stats = player:FindFirstChild("leaderstats") or Instance.new("IntValue", player)
stats.Name = "leaderstats"
local stage = Instance.new("IntValue", stats)
stage.Name = "Stage"
-- Every time they get a new body, put it on their checkpoint.
player.CharacterAdded:connect(function(character)
local pad = pads:FindFirstChild("Checkpoint" .. stage.Value)
if pad then
wait(0.1)
character.Torso.CFrame = CFrame.new(pad.Position + Vector3.new(0, 4, 0))
end
end)
end
-- Make each pad save the stage of whoever touches it.
for _, pad in ipairs(pads:GetChildren()) do
local number = tonumber(string.match(pad.Name, "^Checkpoint(%d+)$") or "")
if number and pad:IsA("BasePart") then
pad.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local stats = player and player:FindFirstChild("leaderstats")
local stage = stats and stats:FindFirstChild("Stage")
if stage and stage.Value < number then
stage.Value = number
local sound = Instance.new("Sound", pad)
sound.SoundId = "brixborg:ding"
sound:Play()
game:GetService("Debris"):AddItem(sound, 2)
end
end)
end
end
game.Players.PlayerAdded:connect(setUp)
for _, player in ipairs(game.Players:GetPlayers()) do setUp(player) end