So I'm trying to use Data Store to store to stats, but for some reason, the too stats are always the same when they load. In game though, they will be changed normaly. But upon joining a game, both the stats are set to the same value. Here is my script:
local ds = game:GetService("DataStoreService"):GetDataStore("mySecretKey") --not my actual thinger
game.Players.PlayerAdded:connect(function(plr)
plr:WaitForDataReady() -- make sure we aren't looking for leaderstats before they are created
local uk = ("ithatofd"..plr.userId)
local stats = plr:FindFirstChild("leaderstats"):GetChildren()
for i=1, #stats do
stats[i].Value = ds:GetAsync(uk)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
plr:WaitForDataReady() -- make sure we aren't looking for leaderstats before they are created
local uk = ("ithatofd"..plr.userId)
local stats2 = plr:FindFirstChild("leaderstats"):GetChildren()
for i=1, #stats2 do
ds:SetAsync(uk, stats2[i].Value)
end
end)
Is there a reason to this?

1 comment
yes! that works perfectly! thank you so much!