DataStore2 how can I wipe/edit a specific key in everyones data?

So I’m making a game and I use datastore2 to handle data saving.

I must be careful with my game as players can lose hard work and progress when they die (it is going to be a permadeath styled game) The game will also have occassional events where certain areas in the map may change in appearance. Or I may decide to add more to the map.

The problem!
When you leave the game it saves the location u logged off at and puts u back when u log in. The issue with this is that lets say someone joins and enters a part of the map. That player walks ontop of a mountain and then logs off. Now lets say I add a house ontop of that mountain. When they log in they will not only be trapped under the house or in a wall. Other players will be flooding around the place as its new content they wish to explore. The poor man trapped in the wall will most likely be brutally murdered and lose progress.

To prevent this I wish to edit everyones spawn location data whenever I add something like this. (or alternatively, if possible, be able to check if their spawn data is near the new location and reset it if it is) I also don’t mind wiping spawn data completely from everyone if I have to as its not a big deal. But I would prefer to be able to edit it.

How can I edit / wipe a single key with datastore from everyone? All help is greatly appreciated!

2 Likes

try the clear command

clear(userId,"key")

type it in the command bar

1 Like

that requires a specific userId. I’m trying to wipe a key from everyone.

well just change the key name then lol

1 Like

? What will that do.
It wont effect everyone only a single player.

change the key to a new one like when the string name of the key

DataStore2.Combine("key","savekeyv2")
1 Like

let me specify on what im trying to achieve.
I want to wipe a key for ALL players. Not just one.

clear(userId,“key”)
requires a userId of a player. I cannot manually get everyones userId and wipe their data that way.

My example wasnt the best so let me use a new one.
Lets say I have a game with currency and a massive dupe exploit comes out and people are getting millions of coins.
How can I wipe the coins of every player. Or edit the data of every player so they only get 100 coins. (Or if possible be able to determine whether someone has over 6000 coins and if they do set their coins to 1000)

Just create a new datastore key and save/load with the new one
it does for all players

1 Like

I don’t know about DS2, but traditionally you need to keep a DataStore with all of the players’ IDs in it.

1 Like

so your saying store all the players IDs in a datastore then iterate through them and edit the data that way?

1 Like

Thats a good way to do it but I’d have to change code everytime due to the key changing also it would leave behind old unused data.

Since you can’t iterate through datastore keys, you’ll have to rename the key (I don’t see any other ways)

1 Like

I know how to edit a specific players data with their userID. However I just need a way to get all the players userids and iterate through them.

changing the key isnt a good option long-term at all. Its more of an emergency thing I would do.

I think there are no other ways to do that except for renaming the key

1 Like

I have an idea of an alternative way but I don’t know how I could execute it.
Is there anyway I can store the IDs of every player who joins into a table? Then save that table as data? Would that cause any problems?

I don’t think it’s a good way to do that if the game has a large amount of players joining servers frequently

You can use an OrderedDataStore, save the value to os.time() and set the key name to the user id (and then retrieve using :GetOrderedDataStore() and iterating through all players), but it seems a bit of an odd/unintended use case if you want to constantly be able to wipe a specific key in everyone’s data. You have to iterate through 1000s of players saved data which doesn’t scale well with Roblox’s data store limits. You’d be better off finding some alternate method to do whatever it is you’re trying to do as I think @aquawrsp is saying (for which it might be the case it’s easier to connect to DataStoreService yourself rather than using DS2).

1 Like

The data store limit will prevent me from setting everyones data too fast correct?

Yes, see Data Stores | Roblox Creator Documentation (Error Codes and Limits section).
Roblox won’t queue queue requests past 30 so you have to be careful not to exceed the limit or you’ll end up silently dropping requests.

1 Like