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

How To Change Part Position When :invert() Was Used In Weld Script?

Asked by 8 years ago

Ok so I am trying to make elevator door and I want to make it move like in real life: move both doors 1 stud away from entrance, move left door to left side, move right door to right side. This is what I used in script to weld these doors:

local doorH = game.Workspace.DoorHandle
local doorL = game.Workspace.DoorLeft

local weld = Instance.new("ManualWeld", doorL)

weld.Part0 = doorL
weld.Part1 = doorH

weld.C0 = doorL.CFrame:inverse() * doorH.CFrame()

And now I need to find a way how to make left door move. This is what I tried in other script: game.Workspace.DoorLeft.ManualWeld.C0 = game.Workspace.DoorLeft.CFrame * CFrame.new(1, 0, 0) But then door teleported somewhere far away, next I tried: game.Workspace.DoorLeft.ManualWeld.C0 = game.Workspace.DoorHandle.CFrame * CFrame.new(1, 0, 0) Same thing happen. I tried a lot of stuff like this and I failed, that's why I'm here asking for help.

1 answer

Log in to vote
0
Answered by 8 years ago

You're dealing with object space
Local space, if you prefer.

What most people don't really understand is that weld.C0 = doorL.CFrame:inverse() * doorH.CFrame() converts doorH.CFrame (Which shouldn't have the parentheses, mind) into doorL.CFrame's Object Space. This means that the new CFrame is relative to doorL.CFrame instead of CFrame.new(0,0,0) (Which is world/global space).

What this means for you is that in order to adjust it, you have to adjust it relative to local space. You'll want to try something like

game.Workspace.DoorLeft.ManualWeld.C0 = game.Workspace.DoorLeft.ManualWeld.C0  * CFrame.new(1, 0, 0)

But for an incremental for loop, you might be better off converting everything from world space to object space with an offset, as you'd done when you welded them originally.

Ad

Answer this question