How can I Make Two Parts Weld On Touch?

I am trying to get the meshpart of my vehicle I created to automatically weld to a part of a truck on touch. I do not know exactly how to accomplish this task.

1 Like
local weldDebounce = false
script.Parent.Touched:Connect(function(hit)
     if hit.Parent.Name == "Truck" and hit.Name == "whatever part you want welded" and weldDebounce == false then
          weldDebounce = true
          local weld = Instance.new("WeldConstraint")
          weld.Parent = script.Parent
          weld.Part0 = hit
          weld.Part1 = script.Parent
          weldDebounce = false
          --script:Destroy()
          --uncomment the line above if it's a one-time script
     end
end)

Make sure it is a normal script inside the part you want welded to the truck.

2 Likes

Originally I thought it was working but it doesn’t seem to weld together.

script.Parent.Touched:Connect(function(hit)
     if hit.Parent.Name == "front car" and hit.Name == "back of truck" and weldDebounce == false then
          weldDebounce = true
          local weld = Instance.new("WeldConstraint")
          weld.Parent = script.Parent
          weld.Part0 = hit
          weld.Part1 = script.Parent
          weldDebounce = false
          --script:Destroy()
          --uncomment the line above if it's a one-time script
     end
end)

https://youtu.be/L0RZOIOP-7E This is the footage of it.

Make sure the boxes of said parts are actually touching (when you select them, the blue lines around it), and if that doesn’t work, change WeldConstraint to just Weld. Welds are less reliable, but if this doesn’t work, then they’re your best bet.
If you use the mesh geometry as the collision boxes, I don’t know how well this will work.

2 Likes

After watching the video a bit more, it might have to do with the angles of the parts.