So, im pretty annoyed/stressed because of the checkpoint script in my game, it just wont work, i tried many, many, MANY, different ones, and yeah, some worked, but not perfectly.
So if anyone has a checkpoint script that ACTUALLY works, i’ll be the happiest.
What i want in the script → (Just like any popular obby games, a checkpoint script, with the leaderstats fx “rasmusx157 - Level - 5” and yeah you get the point basically.
Note: That many of my tries, where made from AI, specifically ChatGPT, so maybe that’s why.
Extra note: That my checkpoint names are “01, 02, … 09, 10 and 11” and the check. script name is “CheckpointScript”
Don’t use AI-generated script if it doesn’t work, write by yourself. It’s not that hard once you know Lua Syntax & A Little Bit Of Roblox Engine API Reference.
normally I dont just give out scripts but I’m making an exception since this is a very simple one.
local checkpoints = workspace.Checkpoints
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Parent = leaderstats
stage.Value = 1
plr.CharacterAdded:Connect(function(char)
task.wait()
if stage.Value > 1 then
char:MoveTo(checkpoints:FindFirstChild(stage.Value - 1).Position)
end
end)
end)
for i, v in pairs(checkpoints:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local char = hit.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local stage = plr.leaderstats.Stage
if tonumber(v.Name) == stage.Value then
stage.Value += 1
end
end
end)
end
Pretty much when a player is added it adds the leaderstats to the players and all the leaderstat values. If that doesnt make sense then there are like 999999+ tutorials on leaderstats that you can follow. Inside of this player added function we’re also detecting character added, and this will fire every time the player’s character loads in. When this happens we just teleport them to their checkpoint
as for the for loop, we’re just looping through a folder with all the checkpoints. If a checkpoint gets touched we check if it was a player. If it was a player, then we set their stage leaderstat.
For this code to work you’ll need a folder in workspace called “Checkpoints”
Add a bunch of parts into the checkpoints folder, those are your checkpoints.
Name these checkpoints with a number for each one. This number will change where the player spawns depending on their stage.
Also maybe next time try searching more, there are sooo many obby tutorials out there
local module = {}
module.__index = module
function module:SaveCheckPoint(checkpoint: BasePart, Level: number): ()
self.checkpoint = checkpoint
self.level = Level
end
function module:GetLevel(): number
return self.level
ens
function module:GetCheckPoint(): BasePart?
return self.checkpoint
end
local new = function(plr: Player)
return setmetatable({
plr = plr,
checkpoint = nil :: BasePart,
level = 0,
}, module)
end
return {new = new}
And create Server script
local Players = game:GetService('Players')
local checkPointsSaver = require(--[[ModuleScript]])
local checkpoint_List = {} -- The List of the checkpoints
local PlayersDataCheckPoints = {}
Players.PlayerAdded:Connect(function(plr)
local localData = checkPointsSaver.new(plr)
table.insert(
PlayersDataCheckPoints,
plr.UserId,
localData
)
plr.CharacterAdded:Connect(function(char)
local checkpoint = localData:GetCheckPoint()
if not checkpoint then return end
char:PivotTo(checkpoint.CFrame + Vector3.yAxis*8)
end)
end)
for _, x in checkpoint_List do
x.Touched:Connect(function(obj)
local plr = Players:GetPlayerFromCharacter(obj.Parent)
if not plr then return end
local PlayerData = PlayersDataCheckPoints[plr.UserId]
local checkpointLevel = table.find(checkpoint_list, x)
if checkpointLevel <= PlayerData:GetLevel() then return end
PlayerData:SaveCheckPoint(x, checkpointLevel)
end
end
I don’t know if it works because I wrote this code on phone.