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.
This function removes the given key from the provided
GlobalDataStore and returns the value that was associated with that key. If the key is not found in the data store, this function returns
If this function throws an error, the
Articles/Datastore Errors|error message will describe the problem. Note that there are also
Articles/Datastore Errors|limits that apply to this function.
Articles/Data store|Data Stores article for an in-depth guide on data structure, management, error handling, etc.
The key identifying the entry being retrieved from the data store
The value that was associated with the data store key, or
Remove Player Data Store
This example removes a player’s data store when they leave the game and prints its value at the time of removal.
local sampleDataStore = game:GetService("DataStoreService"):GetDataStore("MyDataStore") game.Players.PlayerRemoving:Connect(function(player) local playerKey = "Player_" .. player.UserId local success, val = pcall(function() return sampleDataStore:RemoveAsync(playerKey) end) if success then print(val) end end)