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

SetAsync

Sets the value of the key. This overwrites any existing data stored in the key.

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

The value of the entry in the data store with the given key

Returns

Return Type Summary

No return


Code Samples


Reset Player Data Store

The following example is how you would generally use GlobalDataStore/SetAsync|SetAsync(). However, if more than one server will likely be writing to this key, it’s recommended that you use GlobalDataStore/UpdateAsync|UpdateAsync() instead.

local visitsDataStore = game:GetService("DataStoreService"):GetDataStore("PlayerVisits")

game.Players.PlayerAdded:Connect(function(player)
	local playerKey = "Player_" .. player.UserId
	local success, err = pcall(function()
		visitsDataStore:SetAsync(playerKey, 0)
	end)
end)