How can I edit the datastore of an offline user?

For say, a user got first place in a contest and the first place reward was 450 coins. How could I edit that players coins without them being in the server?

1 Like

If you can find their key, you can change their data. For example:

dataStore:SetAsync(playersKey, data)
1 Like

How could we find the users key?

As long as you have it set up so that a certain key is associated with a certain player, it will not matter if a player is online or not. Just save the new coin value to the player’s DataStore “key” just as you would normally, as @P1X3L_K1NG suggested.

1 Like

I am assuming since you are able to detect when they won the contest you have either their name or UserId stored and that’s already half of the work done.

From there it’s really much of the same as you would typically go about saving their DataStore. If you have their UserId you can just plug that in to the DataStore key and voila, however if you have their username and not their UserId you can use game.Players:GetUserIdFromNameAsync and plug in their username to find it.

You might also find it increasingly useful to get a good understand of how GetAsync returns values and then in-turn changing those values and saving them back into the DataStore - that is if you don’t have a good understanding already.

1 Like

whenever you save any data, you create a key for that user using their UserId (along with a string if you decide to). Then that becomes their key.

dataStore:SetAsync(UserId.."-Coins", data)
-- Their UserId and that string becomes their key

whenever you want to change that data, you can get their key by getting their UserId, and simply adding that string

dataStore:SetAsync(key, data)
-- key might look something like this: 12345678-Coins
4 Likes