So I have a script which gives you a level when you reach a certain stage in my obby. But whenever I leave the stats don’t save my data and I restart, can anyone help?
The script;local STAT_NAME = “Level”
local PREVENT_SKIPPING = true
local FolderForCheckpoint = {}
local i = 1
while true do
local checkpoint = Workspace:FindFirstChild("Checkpoint " … i, true)
if not checkpoint then print("Last Checkpoint : " … i-1) break end
table.insert(FolderForCheckpoint, checkpoint)
i = i + 1
end
game.Players.PlayerAdded:connect(function(player)
local leaderstats = player:FindFirstChild(“leaderstats”) or Instance.new(“Model”, player)
leaderstats.Name = “leaderstats”
local checkpointStat = Instance.new("IntValue", leaderstats)
checkpointStat.Name = STAT_NAME
checkpointStat.Value = 1
player.CharacterAdded:connect(function(character)
local goto = FolderForCheckpoint[checkpointStat.Value]
if goto then
repeat wait() until character.Parent
character:MoveTo(goto.Position)
else
warn("Checkpoint " .. checkpointStat.Value .. " not found")
end
end)
end)
for index, checkpoint in ipairs(FolderForCheckpoint) do
checkpoint.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
local humanoid = hit.Parent:FindFirstChild(“Humanoid”)
if not humanoid or humanoid.Health <= 0 then return end
local leaderstats = player:FindFirstChild(“leaderstats”)
if not leaderstats then return end
local checkpointStat = leaderstats:FindFirstChild(STAT_NAME)
if not leaderstats then return end
if (PREVENT_SKIPPING and checkpointStat.Value + 1 == index) or (not PREVENT_SKIPPING and checkpointStat.Value < index) then
checkpointStat.Value = index
end
end)
end