Why Is My Save Tools When Eliminated Or Leaving Not Working?

local dss = game:GetService(“DataStoreService”)
local toolsDS = dss:GetDataStore(“ToolsData”)

local toolsFolder = game.ServerStorage.Tools

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

local toolsSaved = toolsDS:GetAsync(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.ChracterRemoving: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()
	
	toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
end)
if errormsg then warn(errormsg) end

end)

Maybe the problem is that you have an mistake in the initialization of the CharacterRemoving event?

You wrote

plr.ChracterRemoving:Connect(function(char)
	char.Humanoid:UnequipTools()
end)

with ChracterRemoving instead of CharacterRemoving

Let me know if the problem persists!

2 Likes