Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is this part welding wierdly?

Problem: The following welding script makes the part, go INSIDE the torso when played, I want to know how i can have it at it's original position.

No errors in output

Script

-- this script is in every body part but the torso (right/left leg and arm, and head)
Part = script.Parent
MainPart = script.Parent.Parent.Torso


  local w = Instance.new("Weld")
  w.Part1 = MainPart
  w.Part0 = Part
  w.Parent = Part

1 answer

In order to get the weld in the relative position, you have to use CFrame:inverse() Why? Good question. I'm sure someone will comment or answer with an explanation; It's most likely math related, e.g. matrices and such.

Part = script.Parent
MainPart = script.Parent.Parent.Torso


local w = Instance.new("Weld")
w.C1 = MainPart.CFrame:inverse() * Part.CFrame
w.Part1 = MainPart
w.Part0 = Part
w.Parent = Part

For future reference, try checking out the wiki -- That's where I first saw how to do this.

This discussion is preserved as it was. New answers, comments, and votes are closed.