so my script here is having a problem when the player leaves. It makes it to the data ready print but then doesnt get any farther than that. Do you see anything wrong that im doing?
local datastore = game:GetService("DataStoreService"):GetDataStore("PlayerStats")
print("cash datastore created")
game.Players.PlayerAdded:connect(function(newPlayer)
print("EnteredGame")
--newPlayer:WaitForDataReady()
print("data ready")
local stats2 = newPlayer:WaitForChild("leaderstats")
stats2.Cash.Value = datastore:GetAsync(newPlayer.userId .. "Cash")
print("Loaded stats")
wait(1)
datastore:SetAsync(newPlayer.userId .. "Cash", stats2.Cash.Value)
print("Saved stats")
end)
game.Players.PlayerRemoving:connect(function(player)
print("ExitedGame")
--player:WaitForDataReady()
print("data ready")
--wait(2)
local stats = player.leaderstats
print("got leaderstats")
datastore:SetAsync(player.userId .. "Cash", stats.Cash.Value)
print("Saved stats")
end)
game.OnClose = function()
print("begin game close")
wait(2)
print("end game close")
end |