How to clone tool's children

Hello!

I have a problem in my script where it only clones the tool itself and the handle, but doesn’t clone any other children of the tool.

I don’t know if I am doing something wrong or that is not a thing. Is there any other way of doing this?

My current code:

if Answer == true then
		if RepliStorage.ItemAssets:FindFirstChild(selectedItem) then
			local toolRep = RepliStorage.ItemAssets:FindFirstChild(selectedItem)
			if toolRep then
				local Clonedtool = toolRep:Clone()
				Clonedtool.Parent = plr.Backpack
				Clonedtool.Name = selectedItem
				Item = selectedItem
				ItemCost = selectedCost
				
				local Handle = Clonedtool:WaitForChild("Handle")
				
				local Children = {}
				
				for _, child in pairs(Clonedtool:GetDescendants()) do
					if child ~= Handle then
						table.insert(Children, child)
					end
				end
				print(Children)
				

				if Clonedtool then
					for _, child in Clonedtool:GetChildren() do
						if child.Name ~= "Handle" then
							local clonedChild = child:Clone()
							clonedChild.Parent = Clonedtool
						end
					end
				end

			end

Also where it says print(Children) it did print the children of the tool, but after that it doesn’t :Clone the children.

I have made a discovery!

If i make the parent of the children, plr.Backpack it does get cloned but when I move it to the tool, I do not see any of the parts (the children of the tool) apart from the handle.

Also would it be easier to have a picture of the tool, instead of multiple parts in a tool. As used in Roblox Disch.

Your game you chose but whatever your stronger at drawing or modeling/building

Also rather then doing the child.Name ~= “Handle” then. Maybe try

If child.Name == "Handle" then continue end

I haven’t tried drawing it, I’ve made all the models of the tool. But do you know what I can fix in my script above?

Also if you make all the parts to a union will it work?

Yes making the tool into a uinon will work if its roblox made parts not from modeling places likr blender

Its all made out of normal parts, which also includes cylinders. I will try that.

If you cloned a tool you know its children will also be cloned? So if thats you problem. Also theres no reason to set its name to the selecteditem because all of the properties get cloned too

Also funnly im also making a virson of disch for my yt channel where you search in dumpsters.

Yes now it works!!!

Thats good

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.