Weld everything but 1?

So I have this weld script, and it welds EVERYTHING, which is what I want right? But theres 1 specific thing I don’t want welded and its named “WheelPart” how do I make it so it welds everything but that? when I do “and not v.Name == “WheelPart” then” it just breaks, any help?

local P	= script.Parent
local mainPart	= P.Parent.Driving.Base

local weldedParts = {}
table.insert(weldedParts,mainPart)

function Weld(x, y)
	weld = Instance.new("Weld") 
	weld.Part0 = x
	weld.Part1 = y
	local CJ = CFrame.new(x.Position) 
	weld.C0 = x.CFrame:inverse() * CJ  
	weld.C1 = y.CFrame:inverse() * CJ  
	weld.Parent = x	
	table.insert(weldedParts,y)
end

function WeldRec(instance)
	local childs = instance:GetChildren()
	for _,v in pairs(childs) do
		if v:IsA("BasePart") then
			Weld(mainPart, v)
		end
		WeldRec(v)
	end	
end

WeldRec(P)
--WeldRec(P.Parent.Lights)

for _,v in pairs(weldedParts) do
	if v:IsA("BasePart") then
		v.Anchored = false
	end
end

script:Destroy()
1 Like

I think the reason the if statement isn’t working is because you can’t use not with an == (or anything like that). Instead, use ~=. This should fix your issue.

1 Like

Try not to reinvent the wheel - you can use ~= (not equal to) instead of not v.Name == "WheelPart". The reason why it didn’t work is because not v.Name will evaluate to true before performing the operator’s function

You can do if not (v.Name == "WheelPart") but i’d advise to use this:

if v:IsA("BasePart") and v.Name ~= "WheelPart" then
3 Likes