Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i move a welded parts position?

Asked by 5 years ago

Whenever I weld apart, it moves to a random position. How can I move it and rotate it etc.? When I weld it just moves to a random position and I can't move it without the weld breaking. I am using a weld constraint not a script. I would love it if you could help.

0
Where would i place the script? pinelemongamer 19 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Welds have two CFrame which are able to control offset/rotation of the weld, called C0 and C1. When you create a weld, these two offset values are both initially CFrame.new(0,0,0). This means that the two welded parts will end up on top of each other.

If when you weld, you want to keep the parts positioned where they were originally, you can use CFrame:inverse() for C0 and C1, as follows

local a = game.Workspace.PartA
local b = game.Workspace.PartB

local w = Instance.new("Weld")
w.Part0 = a
w.Part1 = b
w.C0 = a.CFrame:inverse()
w.C1 = b.CFrame:inverse()
w.Parent = game.Workspace

Hope this helps, happy coding :)

Ad

Answer this question