Issue with GetChildren

I’ve been trying to make a script that puts the tool model in your hip / back but I’m having issues using tools with multiple parts.

This is my current script

while wait() do
	if script.Parent.Parent.Name == "Backpack" then
		local Chararacter = script.Parent.Parent.Parent.Character

		if Chararacter then
			local Torso = Chararacter:FindFirstChild("Torso")
			local Weapon = Chararacter:FindFirstChild(script.Parent.Name)

			if Torso and not Weapon then
				local WeaponOnLeg = Instance.new("Model")
				WeaponOnLeg.Name = script.Parent.Name
				WeaponOnLeg.Parent = Chararacter

				Handle = script.Parent:GetChildren()
				for i, child in pairs(Handle) do	
				if child:IsA("Part") then child:Clone()
				child.Parent = WeaponOnLeg
						
				local LegWeld = Instance.new("Weld")
				LegWeld.Name = "WeldOnLeg"
				LegWeld.Part0 = Torso
				LegWeld.Part1 = child
				LegWeld.C0 = CFrame.new(0,0,0)
				LegWeld.C0 = LegWeld.C0 * CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(0),math.rad(0))
				LegWeld.Parent = Handle
			end
		end

	else
		if Handle.Parent then 
				Handle.Parent:Destroy()
				end
			end
		end
	end
end

error is
invalid argument #3 (Instance expected, got table)

1 Like

It’s probably erroring at LegWeld.Parent = Handle.

This is a difference in behavior between what your code expects from Handle and what you put in Handle.

You’re putting a table in Handle. So, you can’t set an Instance’s parent to it. Instances can’t be parented to tables. Yet your code expects Handle to be an Instance, not a table.

1 Like

You probably need an end right after LegWeld.Parent = Handle . I don’t see an end for the loop you’re using.

1 Like

GetChildren() returns a table, not an Instance. The ‘in pairs’ sorts through the table, “i” being the index and “child” being the value.
Because GetChildren() is a table of all the Instance’s children, which are also Instances, It cannot be an Instance’s Parent.

So it looks like Legweld.Parent needs to be set to the variable child.

2 Likes