local key = "user-" .. player.userId
local storeditems = datastore:GetAsync(key)
if storeditems then
Level.Value = storeditems[1]
RealLevel.Value = storeditems[1]
XP.Value = storeditems[2]
RealXP.Value = storeditems[2]
Tries.Value = storeditems[3]
RealTries.Value = storeditems[3]
Kills.Value = storeditems[4]
RealKills.Value = storeditems[4]
else
local items = {Level.Value,RealLevel.Value, RealXP.Value, XP.Value, Tries.Value, RealTries.Value, Kills.Value, RealKills.Value}
datastore:SetAsync(key, items)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local items = {player.leaderstats1.Level.Value, player.leaderstats1.XP.Value, player.leaderstats1.Tries.Value, player.leaderstats1.Kills.Value}
local key = "user-" .. player.userId
datastore:SetAsync(key, items)
wait(3)
print(player.Name.."Left The Game")
✓ ANSWER ACCEPTED
How do i make this datastore save every 60 secounts?
1 answer
✓ Accepted answer
while wait(60) true do
for _, v in pairs(game.Players:GetPlayers()) do
saveStats(v)
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Use a "while wait(60) do" loop