How to change someone's data and using datastore

Trying to change someoes member value from 1 to 0 indicating that they are no longer in the leaders party.

I’ve managed to get the players data but I am having trouble changing it and setting it back using SetAsync.

This is the script I have so far and it doesn’t seem to change the players data.
image

Any help is appreciated!

1 Like

If you’re trying to save your player’s data, you should be using SetAsync, not UpdateAsync. UpdateAsync is used to compare your changed values, not save them into the datastore.

What you are trying to achieve is still a gray area to me, but one thing I can tell you is that if you are 100% certain that you are only going to have the values 1 and 0 for a given data, you shouldn’t use operations like + or - because let’s say someone were to fire an event to the server more than once in the matter of a second, the value will keep decreasing and will eventually go below 0 as a result.

I’ve tried using SetAsync but it wont set the Value after I changed it, it prints that its changed but when I look back at my stats in the explorer it didn’t

Are you trying to change the stat in the leaderboard too? Saving to a datstore won’t automatically change the leaderstat. You would have to manually change that as well.

Can you explain further please?

The Datastore and the leaderboard stat itself are not related. Say that you have a stat named “Points” on the leaderboard next to a player’s name. If you change a Datastore value for a player also named “Points” it won’t change the leaderboard just because they happen to have the same name. If you want to change the value on the leaderboard, you may want to check out this article about Leaderstats.

Specifically to change a stat on the leaderboard you will have to find the Value object and change its value. For example, you have a player named “xipped”, who has a stat named “Points”. To change xipped’s points on the leaderboard, you would first want to access the player xipped, from game.Players. Then you want to find xipped’s leaderstats folder. game.Players.xipped.leaderstats. Then you would want to access the “Points” object in leaderstats. game.Players.xipped.leaderstats.Points. And to make it easier, let us set a reference. So the final reference might look like

local pts = game.Players.xipped.leaderstats.Points

And to increment this we would access its value:

pts.Value = pts.Value + 1

This is all assuming that you have already set up the leaderstats folder for the player. I highly suggest you look at the linked article. My main point is that just changing the datastore won’t change a value on the leaderboard, and vice versa. You have to manually change both.

Didn’t you make a thread on this already? Thought you fixed it.

This isn’t my goal, my goal is actually to change the data of an offline player, like you can kick them out of your party without them being in your server and there is no way I can access the folder on it.

Yes I fixed getting the data, but changing it is a problem.

Well if you can get it, you can set it.

Changing the data of an offline player is the same as changing the data of an online one. The problem is getting the player’s ID to change the key to the datastore. There is no difference in actually setting the value.

This changes the data of the player that fires the remote.

It’s not setting somehow.
image it shows its changed
but looking in the explorer it hasn’t.
image

What makes you think that changing the datastore will change the NumberValue “Member”?

You never change the value so… This is why I told you to use modules.

How do I change the value though?

False, UpdateAsync can be used for updating. It does a GET request to the datastores, you can edit the data, and then return a value to set the data.

From what I see, it looks like you’re returning newValue? That replaces the players data from your data table to just the value of newValue.

You need to find a reference to it. If your value is in the workspace then you would do game.Workspace.Member.Value = somenumber

Get the NumberValue instance you’re trying to modify, set the value when you update the “newValue”.

Okay, so I made a numbervalue Instance and set the Value as the member value I got from the player. changed the NumberValue Instance and set it again, do you think it would work?
image