Hello!
I'm making a game, and I want people's KOs to save through its alpha stages.
I've tried to write this code multiple times, and it never works.
I have the basic leaderstats script, except I changed "KOs" and "Wipeouts" to "Kills" and "Deaths".
It's supposed to keep a running value of kills and deaths; if you leave the game at 2 kills, you'll come back with 2, if you leave with 4, next time you come back, you'll have 4.
Here's the saving script:
local KOStore = game:GetService("DataStoreService"):GetDataStore("KO")
local WOStore = game:GetService("DataStoreService"):GetDataStore("WO")
game.Players.PlayerAdded:connect(function(plr)
plr:WaitForChild("leaderstats")
plr.leaderstats:WaitForChild("Kills")
plr.leaderstats:WaitForChild("Deaths")
local KOkey,WOkey = "user_"..plr.userId.."KO","user_"..plr.userId.."WO"
plr.leaderstats.Kills.Value,plr.leaderstats.Deaths.Value = KOStore:GetAsync(KOkey),WOStore:GetAsync(WOkey)
end)
game.Players.PlayerRemoving:connect(function(plr)
local KOkey,WOkey = "user_"..plr.userId.."KO","user_"..plr.userId.."WO"
KOStore:UpdateAsync(KOkey,function(oldValue)
if oldValue then
return (oldValue + plr.leaderstats.Kills.Value)
else
return (plr.leaderstats.Kills.Value)
end
end)
end)
I've tested this both on studio servers and actual servers, and it doesn't work on either.

1 comment
Anyone? :/