✓ Accepted answer
Here's a nifty solution for you. While I don't know what exactly was wrong with your original code, this modified code will do what you're hoping for.
Essentially, this will rename tools which you own to your tool, and then move them to ServerStorage, transporting them back to you after you respawn. If you need tools to be named something specific and this will interfere with something, I'm sure you can come up with a different method to sift through the tools in ServerStorage - such as a StringValue inside each tool.
I also made it so it will return the tool you are holding as well - which I moved by using FindFirstChildOfClass() inside of Character.
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character)
for _,v in pairs(game.ServerStorage:GetChildren()) do
if string.sub(v.Name, 1, string.len(player.Name)) == player.Name then
v.Parent = player.Backpack
end
end
Character:WaitForChild("Humanoid").Died:Connect(function()
for _,v in pairs(player.Backpack:GetChildren()) do
v.Parent = game.ServerStorage
end
if Character:FindFirstChildOfClass("Tool") ~= nil then
Character:FindFirstChildOfClass("Tool").Name = (tostring(player).."'s tool")
Character:FindFirstChildOfClass("Tool").Parent = game.ServerStorage
end
end)
end)
player:WaitForChild("Backpack").ChildAdded:Connect(function(tool)
tool.Name = (tostring(player).."'s tool")
end)
end)
2 comments
Any purpose for a tool to be inside of a tool? Can't they just be seperate? Use a folder if you're organizing things inside it.
no i have things inside my tools