PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

RemoveAsync

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 nil.

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.

See the Articles/Data store|Data Stores article for an in-depth guide on data structure, management, error handling, etc.

Parameters

Name Type Default Description

key

The key identifying the entry being retrieved from the data store

Returns

Return Type Summary

The value that was associated with the data store key, or nil if the key was not found


Code Samples


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)