trying to get the leaderstats to save but its not working, the cash does go up but, the data isn't saving. is there anything im missing?
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("IntValue",player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue",leaderstats)
cash.Name = "RPCash"
cash.Value = 0
cash.Parent = leaderstats
local reward = 1
while true do
wait(5)
cash.Value = cash.Value + reward
end
DataStore = game:GetService("DataStoreService"):GetDataStore("SaveCash")
local Key = player.userId
local Data = DataStore:GetAsync(Key)
if Data then
cash.Value = Data
end
end)
game.Players.ChildRemoved:connect(function(Player)
local Key = Player.userId
DataStore:SetAsync(Key,Player.leaderstats.Cash.Value)
end)

7 comments
Please indent your code how the hell do expect us to read that mess
Also why is DataStore a global variable and this code is completely screwed
we all learn from our mistakes.. i'll keep looking around and see if i find a solution.. thanks :/
You never got to the saving part because the while true do loop never ends, preventing the code below it from executing.
yea u got a point. i'll try something out later. Happy holidays man.
That's completely wrong @Rheines
Yeah I realized my mistake after