Returns no errors.
DataStore = game:GetService("DataStoreService"):GetDataStore("BSI")
Players = game:GetService("Players")
game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "stats"
local Level = Instance.new("IntValue", stats)
Level.Name = "Level"
Level.Value = 1
local leader = Instance.new("IntValue", player)
leader.Name = "leaderstats"
local Kills = Instance.new("IntValue", leader)
Kills.Name = "Kills"
local key = "user "..player.userId
local Saved = DataStore:GetAsync(key, function(Saved)
print (Saved) --doesn't print
Kills.Value = Saved or 0
DataStore:SetAsync(key, Saved)
print (key, Saved) --does not print
end)
end)
game.Players.PlayerRemoving:connect(function(player)
local key = "user "..player.userId
print (key.." left") --prints correctly
local Saved = player.leaderstats.Kills.Value
print (Saved.." value") --prints correctly
DataStore:UpdateAsync(key, function(Saved)
print (key, Saved) --print incorrectly, the key is always right, but saved is always 0
end)
end)

1 comment
I think it's because you're replacing Saved when specifying the argument in your function, which will make it equal 0. Try changing the argument to a different name like Savedata.