Hey, so today i've been trying to save a number value that is located in
workspace.Remotes.PlayerValues[playername].ExtraLives
Then loading the value into
workspace.Remotes.PlayerValues[playername].ChangeEL
But when I enter the game, change my value to something above 0, leave, then rejoin, the value doesn't load.
The following code is what I am using to Save/Load but it doesn't seem to be working and it doesn't give any errors.
ds = game:GetService("DataStoreService"):GetDataStore("Lives")
game.Players.PlayerAdded:connect(function(player)
repeat wait() until workspace.Remotes.PlayerValues:FindFirstChild(player.Name)~=nil and workspace.Remotes.PlayerValues:FindFirstChild(player.Name).ChangeEL.Script.Disabled==false
local lives = workspace.Remotes.PlayerValues:FindFirstChild(player.Name).ChangeEL
lives.Value = ds:GetAsync(player.Name) or 0
end)
game.Players.PlayerRemoving:connect(function(player)
ds:UpdateAsync(player.Name, function(oldValue) return workspace.Remotes.PlayerValues:FindFirstChild(player.Name).ExtraLives.Value end)
end)
game.OnClose = function()
for i,v in pairs(game.Players:GetChildren()) do
ds:UpdateAsync(v.Name, function(oldValue) return workspace.Remotes.PlayerValues:FindFirstChild(v.Name).ExtraLives.Value end)
end
wait(1)
end
Thank you.

5 comments
If you're not using the old value, you can just use :SetAsync() instead of :UpdateAsync()
"workspace.Remotes.PlayerValues:FindFirstChild(player.Name).ExtraLives" will error if the playerthing isn't found, as FindFirstChild() would return nil, so you're doing (nil).ExtraLives, aka indexing a nil value.
No idea why it doesn't work, though.
@einsteinK Should I try changing :UpdateAsync() to :SetAsync() to see if that works?
And "workspace.Remotes.PlayerValues:FindFirstChild(player.Name).ExtraLives" there is a ~=nil at the end of that but it doesnt seem to be showing.