Trying to make a data reset everytime a player die

Im trying to make a player data reset when they die but I cant figure it out because my tools remains in my inventory and not removed.

local Data = game:GetService("DataStoreService")
local datast= Data:GetDataStore("Data")

game:GetService('Players').PlayerAdded:Connect(function(plr)
	local toolsOwned = {}

	plr.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			local success, errormsg = pcall(function()
				toolsDS:RemoveAsync(plr.UserId .. "-tools", toolsOwned)
			end)
			if errormsg then warn(errormsg) end
			print("Tool Datawipe")
		end)
	end)
end)

Your datastore variable is datast, not toolsDS

fixed it and it still didn’t work

RemoveAsync only takes one parameter, which will be the key to the datastore. So do :RemoveAsync(plr.UserId…“-tools”). You don’t need to include the toolsOwned table.

1 Like

it still haven’t worked is there something else I should do?

Your GetDataStore variable should be the same when calling your GetAsync function as well (Which I’m assuming is in a different script), and you should be using the same key provided when you check for any data inside the Player’s key

Are there any errors being Outputted back?

1 Like

no error in the output and no its in the same script

Can I see where you call the SetAsync() functions then? You could also add a couple print statements, preferably inside when the character dies if it prints correctly

game.Players.PlayerAdded:Connect(function(plr)

	local toolsSaved = datast(plr.UserId .. "-tools") or {}

	for i, toolSaved in pairs(toolsSaved) do

		if toolsFolder:FindFirstChild(toolSaved) then 

			toolsFolder[toolSaved]:Clone().Parent = plr.Backpack
			toolsFolder[toolSaved]:Clone().Parent = plr.StarterGear 
		end
	end

	plr.CharacterRemoving:Connect(function(char)

		char.Humanoid:UnequipTools()
	end)
end)


game.Players.PlayerRemoving:Connect(function(plr)

	local toolsOwned = {}

	for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do

		table.insert(toolsOwned, toolInBackpack.Name)
	end

	local success, errormsg = pcall(function()

		datast(plr.UserId .. "-tools", toolsOwned)
	end)
	if errormsg then warn(errormsg) end
end)