My data is still not saving.
code:
local died = false
local secondsHandler = false
local checkpoints = workspace.Checkpoints
local dss = game:GetService("DataStoreService")
local Datastore = dss:GetDataStore("ObbyData")
local Players = game:GetService("Players")
game:BindToClose(function()
for _,Player in pairs(Players:GetPlayers())do
Player:Kick("This server is shutting down")
end
wait(3)
end)
print("Checkpoints leaderstats working")
print("Deaths leaderstats working")
print("Time leaderstats working")
game.Players.PlayerAdded:Connect(function(plr)
local obbyData = Datastore:GetAsync(plr.UserId .. "-obbyStageProgress")
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local stage = Instance.new("StringValue")
stage.Name = "Stage"
stage.Value = (obbyData and obbyData[1]) or 1
stage.Parent = stats
local wipeouts = Instance.new("IntValue")
local wipeoutsData = Datastore:GetAsync(plr.UserId,wipeouts.Value)
wipeouts.Name = "Deaths"
wipeouts.Value = wipeoutsData
wipeouts.Parent = stats
local second = Instance.new("IntValue")
local secondData = Datastore:GetAsync(plr.UserId,second.Value)
second.Name = "Seconds"
second.Value = secondData
second.Parent = stats
local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[stage.Value].CFrame
char.Humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(stage.Value))or touch.Name == "End"then
stage.Value = touch.Name
end
end
plr.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild("HumanoidRootPart")
local humanoid = char:WaitForChild("Humanoid")
hrp:GetPropertyChangedSignal("CFrame"):Wait()
hrp.CFrame = checkpoints[stage.Value].CFrame
humanoid.Died:Connect(function()
if not died then
died = true
wipeouts.Value = wipeouts.Value + 1
wait(5)
died = false
end
end)
local humanoid = char:WaitForChild("Humanoid")
humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(stage.Value))or touch.Name == "End" then
stage.Value = touch.Name
end
end
end)
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local DatastoreTable = {
player.leaderstats.Stage.Value,
player.leaderstats.Deaths.Value,
player.leaderstats.Seconds.Value
}
local success, fail = pcall(function()
Datastore:SetAsync(player.UserId .. "-obbyStageProgress", DatastoreTable)
end)
if success then print(success) else print(fail) end
end)
while true do
wait()
for _,player in pairs(Players:GetPlayers()) do
wait(1)
player.leaderstats.Seconds.Value = player.leaderstats.Seconds.Value + 1
end
end