RemoveAsync
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts.
For thread safety, this property is not safe to read in an unsynchronized thread.
This function marks the specified key as deleted by creating a new “tombstone” version of the key. Prior to this, it returns the latest version prior to the remove call.
After a key is removed via this function, GlobalDataStore/GetAsync calls for the key will return nil. Older versions of the key remain accessible through DataStore/ListVersionsAsync and DataStore/GetVersionAsync, assuming they have not expired.
OrderedDataStore does not support versioning, so calling GlobalDataStore/RemoveAsync|RemoveAsync() on an OrderedDataStore key will permanently delete it.
If the previous values were already deleted via GlobalDataStore/RemoveAsync or DataStore/RemoveVersionAsync, the function will return nil, nil for value and DataStoreKeyInfo respectively.
See Also
Articles/Data store|Data Stores, an in-depth guide on data structure, management, error handling, etc.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
|
|
Key name to be removed. If |
Returns
| Return Type | Summary |
|---|---|
|
The value of the data store prior to deletion and a |
Code Samples
Remove Data Store Key/Value
local DataStoreService = game:GetService("DataStoreService")
local nicknameStore = DataStoreService:GetDataStore("Nicknames")
local success, removedValue, keyInfo = pcall(function()
return nicknameStore:RemoveAsync("User_1234")
end)
if success then
print(removedName)
print(keyInfo.Version)
print(keyInfo.CreatedTime)
print(keyInfo.UpdatedTime)
print(keyInfo:GetUserIds())
print(keyInfo:GetMetadata())
end