Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How should I go about saving things using DataStorage?

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!

2 answers

✓ Accepted answer

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")

This discussion is preserved as it was. New answers, comments, and votes are closed.