Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my script give me my tools but not the children of the tool?

After going server-side with my backpack save after death script I found another issue with it, It kinda works now but I have an issue that my script clones all the items in my backpack back when I die, but it doesn't clone the children of the tools

game:GetService("Players").PlayerAdded:Connect(function(player)
	repeat wait() until player.Character
	local char = player.Character
	
	char:WaitForChild("Humanoid").Died:Connect(function()
		local tools = player.Backpack:GetChildren()
		
		player.CharacterAdded:Connect(function()
			wait(1)
			
			for i,v in pairs(tools) do
				if v:IsA("Tool") then
					local clonedTool = v:Clone()
					clonedTool.Parent = player.Backpack
				end
			end
		end)
	end)
end)

2 comments

0

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.

0

no i have things inside my tools

2 answers

✓ 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)

1 comment

0

Oh my god, finally a fix to this problem I had for a while, cheers xoxo

you have to do v:getchildren() its the only way

1 comment

0

as a fix to this myself I'd say I'd do tools = player.Backpack:GetDescendands and then loop through the descendants, check what it's parent is and then parent it idk, but i have no idea why this doesnt work

This discussion is preserved as it was. New answers, comments, and votes are closed.