I'm making a car, and I'm making it in a way where there're parts inside of parts in a few places. The script I wrote gets them to weld, but not if they aren't inside of another part. Parts of the script are from the wiki.
local function weldBetween(a, b)
--Make a new Weld and Parent it to a.
if a.ClassName == "Part" or a.ClassName == "UnionOperation" then
local weld = Instance.new("ManualWeld", a)
weld.Part0 = a
weld.Part1 = b
weld.Name = "Weld"
--Get the CFrame of b relative to a.
weld.C0 = a.CFrame:inverse() * b.CFrame
--Return the reference to the weld so that you can change it later.
return weld
end
end
for index, child in pairs(script.Parent:GetChildren()) do
if child.ClassName == "Part" or child.ClassName == "Seat" or child.ClassName == "VehicleSeat" then
weld1 = weldBetween(child, script.Parent.VehicleSeat)
child.Anchored = false
end
end
