local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
 local leader = Instance.new("Folder",player)
 leader.Name = "leaderstats"
 local Cash = Instance.new("IntValue",leader)
 Cash.Name = "Cash"
 Cash.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, Cash.Value)
 Cash.Changed:connect(function()
  ds:SetAsync(player.UserId, Cash.Value)
 end)
end)


game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.leaderstats.Cash.Value) --Something wrong with it?
end)

I want to make a cash saving script with DataStore. Doesn't work! Help me. I think there is something wrong in line 18.

3 comments

0

Your script works. Make sure API Services are enabled, and also make sure you're changing your cash on the server, and not the client.

0

How to do that

0

oh so what i have to do is enable API, ok i'll tell you when its working or not