Answered by
5 years ago Edited 5 years ago
Using * DataStoreService*, the only way you can change a value is by overwriting the former. The same thing applies with removing keys or values as well. Just like how you'd "remove" a variable in a script by setting it to * nil*, you'd do the same thing in data store with whatever set method you're using ( SetAsync, > UpdateAsync, etc) - just save a nil value. Here's an example:
1 | local data = game:GetService( "DataStoreService" ):GetDataStore( "Test" ) |
2 | data:SetAsync( "Key" , "Hello there" ) |
6 | data:SetAsync( "Key" , nil ) |
This example removes a player’s data store when they leave the game and prints its value at the time of removal.
01 | local sampleDataStore = game:GetService( "DataStoreService" ):GetDataStore( "MyDataStore" ) |
03 | game.Players.PlayerRemoving:Connect( function (player) |
04 | local playerKey = "Player_" .. player.UserId |
06 | local success, val = pcall ( function () |
07 | return sampleDataStore:RemoveAsync(playerKey) |