I'm doing a checkpoint system that saves every time the player gets a new checkpoint. The problem is that the player doesn't spawn on the checkpoint,and every time the player leaves and go back to the map the leaderstats go back to 1,even if i change the or to 0. the checkpoint script that is on server scripts.
local DS = game:GetService("DataStoreService")
local PD = DS:GetDataStore("PD")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats= Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local Stage = Instance.new("IntValue", leaderstats)
Stage.Name= "Stage"
Stage.Value = PD:GetAsync(plr.UserId) or 0
PD:SetAsync(plr.UserId, Stage.Value)
Stage.Changed:Connect(function()
local success, Error = pcall(function()
PD:SetAsync(plr.UserId .. "Stage", plr.leaderstats.Stage.Value)
end)
if success then
print("data saved")
else
print("error 2 ")
warn(Error)
end
end)
end)
function checkspawn(players)
local plr=game.Players:GetPlayerFromCharacter(players)
if plr~=nil then
local check=plr.leaderstats
local value = game.workspace:FindFirstChild(check.Stage.Value)
print("obby")
players.HumanoidRootPart.CFrame =players.HumanoidRootPart.CFrame + Vector3.new(0,3,0)
wait()
players.HumanoidRootPart.CFrame = value.CFrame + Vector3.new(0,3,0)
end
end
game.Players.ChildAdded:Connect(checkspawn)
the script on the checkpoints
function ot(hit)
if hit.Parent ~= nil then
local players = game.Players:playerFromCharacter(hit.Parent)
if players ~= nil then
if players.leaderstats.Stage.Value == script.Parent.Name - 1 then
local h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil then
if h.Health ~= 0 then
players.leaderstats.Stage.Value = script.Parent.Name
end
end
end
end
end
end
script.Parent.Touched:connect(ot)

2 comments
Ok,now the values save,but my checkspawn function still not spawning the player on the checkpoints,for some reason my checkspawn function isn't running because the obby isn't printing.
Nevermind I just did the code wrong game.Players.ChildAdded:Connect(checkspawn), here it's actually workspace and GetPlayerFromCharacter(players) here it's actually just player From Character.Now the script is working.