Sorry, there is no errors in the output. This is the simple one as i’m not confident in posting this on the devforum unless it was via a private message
local Data = game:GetService("DataStoreService"):GetDataStore("TEGAME1")
game.Players.PlayerAdded:Connect(function(plr)
local s = Instance.new("Folder",plr)
s.Name = "Stats"
local coins = Instance.new("NumberValue",s)
coins.Name = "Coins"
coins.Value = 0
local rebirths = Instance.new("NumberValue",s)
rebirths.Name = "Rebirths"
rebirths.Value = 0
local Data = Data:GetAsync(tostring(plr.UserId))
if Data then
coins.Value = Data[1] or 0
rebirths.Value = Data[2] or 0
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local stats = plr.Stats
Data:SetAsync(tostring(plr.UserId), {
stats.Coins.Value,
stats.Rebirths.Value,
})
end)
There should be more values, there is only a limited amount as ive been trying to get it to work, i’ve been trying all day near enough.
Swap Data[1] and Data[2] for userid[1] and userid[2] in that person’s answer, though I disagree with the naming of that variable as it’s a table of player data, not a user id.
I assume you’re testing in-game and not in studio right? I see no issue with the code if you’ve made those changes.
Are you changing the values on the client or the server before saving? If on the client then obviously the server version would still be 0 and would save 0 to your datastore.
If in studio I have had a couple of occasions where the game is closed before it saves. Try adding a game:BindToClose( callback ) where callback is a function that either arbitrarily holds it open by doing wait( 30 ) for example, or more appropriately perform a save of all players’ data (loop through game.Players:GetPlayers() and save everyone’s stats).
If you haven’t had an issue before then those games are probably not secure and don’t use Filtering.
In terms of the remote events, any checks you do on the client should be done on the server too, for example a time-based check if it’s free money upon clicking some button regularly. So on the server you’d store when the player last claimed the cash, and check that sufficient time has passed, something along the lines of tick() - lastCashTick >= CASH_TIMEOUT where CASH_TIMEOUT is a variable set to the minimum number of seconds to enforce between claims.