We use cookies on this site to enhance your user experience

Remove Player Data Store

Remove Player Data Store

Sep 05 2018, 8:13 PM PST

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)