I've been trying to save player data lately, but it just hasn't been working and I'm not sure why.
The player's data is stored in a table currently.
There are no errors.
Here is how I update the player's data, as an example:
gp.Changed:connect(function() --fired when a player value changes player_data:UpdateAsync(key, function() return valuesToSave --table containing player values end) end)
To be honest, I'm really confused and don't quite know what I'm doing, so if it's possible some explanation would be great too.
If you need anything else from my scripts, I will edit this.
Thanks for reading!
To save the Table in datastores, just save it regularly:
valuesToSave = {} gp.Changed:connect(function() --All of this is correct, as long as the hierarchy is correct. player_data:UpdateAsync(key, function() return valuesToSave end) end)
This will make everything easier though; use mapping-styled tables:
valuesToSave = {["Gold"] = 54, ["Kills"] = 3} --Then you can do this: leaderstat.Gold.Value = player_daya:GetAsync(key)["Gold"]
It says in the wiki that this method of saving tables is okay as long as you do the ["Test"] = ...
, do not use mixed tables. Make sure "Test" is a STRING(Text).
Hope it helps!
When using DataStores, the tables need to be encoded in JSON. Make sure you know how to do that.
It also could be a problem with requesting too much. Here you can see how many requests per minute you are allowed for any number of players.
Also, this is assuming gp and player_data were defined correctly earlier in the script. Something like this:
player_data = game:GetService("DataStoreService"):GetDataStore("PlayerValueNameHere")