How to reset certain part of a single datastore

Hi so basically i have a single datastore that saves multiple variables like level, experience, fighting style, etc. I am wondering, how can I only reset levels within this datastore without resetting the entire thing?

1 Like

The datastore should be a table for example:

local dataTable = {
    level = 0,
    experience = 0,
    FightingStyle = "Default"
}

dataTable.level = 0

I want to reset a certain part of the datastore entirely not reset it for one player in a single server

you’d save the new datastore on the player.Removing event

It would reset everytime someone leaves?

baiscally,
the datastore should save every time right before the player leaves, for instance:
the player leaves once he hits level 10, then once the player has left it saves his levels as 10 (because he was level 10 when he left).
Now, since you reset the player’s levels to 0 through a script, if he leaves immediately then it will save his levels as 0. If the player doesn’t leave and decides to level up again, he’d have to go from 0 again, since it’s set in the server.

Im sorry but you misunderstood my question I am asking how I can reset a certain part of data foreveryone even if they dont join servers to avoid the reset

Create a new datastore, name it whatever, have a boolean stored as the value and use it to determine whether or not the player’s data has been reset, let’s just say it’s named “IsPlayerDataReset” for now.

Now when a player joins, we check if they have a datastore entry inside “IsPlayerDataReset”, if they do, then we don’t need to reset their data since they’ve already had it reset, now if they don’t have data in said datastore, you can go ahead and reset the specific data entry, and then setasync their “IsPlayerDataReset” to true, so now whenever they rejoin they’ll have data set in that datastore to inform they’ve already had their level reset.

I was thinking something similar along those lines but what if i wanted to do this in the future because the bool will already be true and if i mset it to false again then it would reset the data again

If you really wanted to keep using the same datastore you could store an array as the player’s data instead of just a boolean, and inside said array store a timestamp for each data reset.

1 Like