Code:
local model = game:GetService('Workspace').Checkpoints
for i,v in pairs(model:GetChildren()) do
if v:IsA("BasePart") then
v.Name = i
end
end
local name = "Banna"
local showname = "Checkpoint"
local DSService = game:GetService('DataStoreService'):GetDataStore(name)
game.Players.PlayerAdded:Connect(function(plr)
local uniquekey = 'id-'..plr.userId
local leaderstats = Instance.new('IntValue', plr)
local savevalue = Instance.new('IntValue',leaderstats)
leaderstats.Name = 'leaderstats'
savevalue.Name = showname
savevalue.Value = 1
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved[1]
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
for i,v in pairs(game:GetService('Workspace').Checkpoints:GetChildren()) do
if v:IsA("BasePart") then
if tonumber(savevalue.Value) >= tonumber(v.Name) then
v.BrickColor = BrickColor.new("Medium green")
else
v.BrickColor = BrickColor.new("Persimmon")
end
end
end
plr.CharacterAdded:Connect(function(chr)
chr.Humanoid.Died:Connect(function()
print(plr.Name.." has died.")
local l = plr:FindFirstChild("leaderstats")
local savev = l:FindFirstChild(showname)
plr.CharacterAdded:Wait()
chr:FindFirstChild("HumanoidRootPart").Position = game:GetService('Workspace').Checkpoints:FindFirstChild(savev.Value).Position
end)
if plr:FindFirstChild("leaderstats"):FindFirstChild(showname).Value == 0 then
plr:FindFirstChild("leaderstats"):FindFirstChild(showname).Value = 1
end
for i,v in pairs(model:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
local l = plr:FindFirstChild("leaderstats")
local savev = l:FindFirstChild(showname)
if tonumber(v.Name) > savev.Value then
savevalue.Value = tonumber(v.Name)
end
end
end)
end
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats[showname].Value}
DSService:SetAsync(uniquekey, Savetable)
end)
end)