If thats what you want, you could load the data, then check if the player’s data exists in the returned table, and if so, delete it.
local Data
local Success, errorMessage = pcall(function()
Data = DataStore:GetAsync('ServerKey')
end)
if Success and Data ~= nil then
if table.Find(Data, Player.UserId) then
table.remove(Data, table.Find(Data, Player.UserId))
end
end
Then, reinsert the new data, and update the datastore.
Data[Player.UserId] = NewPlayerData
DataStore:SetAsync('ServerKey', Data)
The data should look something like this:
Data = {
[123456789] = {['Stuff in table']};
[234567890] = {['Stuff in table']};
}
However, DataStores do have limits for the amount of stored data per key (I think) which is why using UserIds is the recommended option.
Also, I havent ever used DataStores like this, but i would assume data loss would be VERY common using then llike this.
Im just going to give a useful list to hopefully avoid most problems you may encounter using this:
-
DO NOT save players game data this way (Money, Inventory items, etc)
- Attempt to keep the saved data to a minimum. A few numbers or strings per player at most
- Only update the datastore when needed, do not call it every few minutes / seconds.
- Keep all data-related stuff to be on the server, unless its required that the clients need information.
Save their UserId, as players can change their username, and then they will lose their data, and exploiters could also (maybe) cheat and use other players data for themselves.
Also with this error, it wouldnt be coming from the code i gave you, as it doesnt use the immersive ads?