Well, I know that removing the startergear part of the script, as fixed but it is not like that since if you do it, the tools are no longer added to the backpack. What I want is that moments after entering the tools are added to the player’s backpack and those of the startergear are eliminated (since when you reappear, the startergear tools are moved to the backpack) and thus when dying, they are not added to backpack
local dss = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local toolsDS = dss:GetDataStore("ToolDataPlayer")
local ServerStorage = game:GetService("ServerStorage")
local toolsFolder = ServerStorage.ToolsFolder
Players.PlayerAdded:Connect(function(plr)
local OwnedTools = toolsDS:GetAsync(plr.UserId)
for _, toolData in pairs(OwnedTools) do
if not toolsFolder:FindFirstChild(toolData.ToolName) then continue end
local Tool = toolsFolder[toolData.ToolName]:Clone()
Tool:WaitForChild("Stack").Value = toolData.Stacks
Tool.Parent = plr.Backpack
local ToolGear = toolsFolder[toolData.ToolName]:Clone()
ToolGear:WaitForChild("Stack").Value = toolData.Stacks
ToolGear.Parent = plr.StarterGear
end
plr.CharacterRemoving:Connect(function(char)
char.Humanoid:UnequipTools()
end)
end)
Players.PlayerRemoving:Connect(function(plr)
local OwnedTools = { }
for i, tool in pairs(plr.Backpack:GetChildren()) do
if not tool:IsA("Tool") then continue end
table.insert(OwnedTools, {ToolName = tool.Name, Stacks = tool.Stack.Value})
end
local success, errormsg = pcall(function()
toolsDS:SetAsync(plr.UserId, OwnedTools)
end)
if errormsg then
warn(errormsg)
end
end)
I thought it might work if I put the “Character Added” function but I knew that the tools would be loading from the datastore, not from the startergear