Help with welding on lift script

I’m making a lift using tweens which works fine, even if it isn’t the most streamlined or optimised. I want to add detail to the lift itself. I tried using weld constraints, both in and out of the script. The result was that the original part which I set as the root part moved, but the detail didn’t move with it. I’m wondering whether this is maybe because I’m using vector3 values rather than CFrame values. Does this matter?

local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local Lift = script.Parent

local Door11 = game.Workspace.Door11
local Door12 = game.Workspace.Door12
local Door21 = game.Workspace.Door21
local Door22 = game.Workspace.Door22
local Door31 = game.Workspace.Door31
local Door32 = game.Workspace.Door32

local CD1 = game.Workspace.Part1.ClickDetector
local CD2 = game.Workspace.Part2.ClickDetector
local CD3 = game.Workspace.Part3.ClickDetector

local LiftGroup = game.Workspace.LiftGroup


for _, Part0 in pairs (LiftGroup:GetChildren()) do
	if Part0:IsA("BasePart") and not (Part0 == Lift) then
		local WeldConstraint = Instance.new("WeldConstraint")
		WeldConstraint.Part0 = Part0
		WeldConstraint.Part1 = Lift
		WeldConstraint.Parent = WeldConstraint.Part0
	end
end

local Tweenfo = TweenInfo.new(
	3,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local Goals1 = 
{
	Position = Vector3.new(0,0,0)
}

local Goals2 = 
{
	Position = Vector3.new(0,15,0)
}

local Goals3 = 
{
	Position = Vector3.new(0,30,0)
}

local TweenLift1 = TweenService:Create(Lift, Tweenfo, Goals1)

local TweenLift2 = TweenService:Create(Lift, Tweenfo, Goals2)

local TweenLift3 = TweenService:Create(Lift, Tweenfo, Goals3)



local DoorOpenTweenfo = TweenInfo.new(
	2,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local DoorGoals11 = {Position = Vector3.new(7.05,7.25,-5)}
local DoorGoals12 = {Position = Vector3.new(-7.05,7.25,-5)}
local DoorGoals21 = {Position = Vector3.new(7.05,22.25,-5)}
local DoorGoals22 = {Position = Vector3.new(-7.05,22.25,-5)}
local DoorGoals31 = {Position = Vector3.new(7.05,37.25,-5)}
local DoorGoals32 = {Position = Vector3.new(-7.05,37.25,-5)}

local DoorCloseGoals11 = {Position = Vector3.new(3.05,7.25,-5)}
local DoorCloseGoals12 = {Position = Vector3.new(-3.05,7.25,-5)}
local DoorCloseGoals21 = {Position = Vector3.new(3.05,22.25,-5)}
local DoorCloseGoals22 = {Position = Vector3.new(-3.05,22.25,-5)}
local DoorCloseGoals31 = {Position = Vector3.new(3.05,37.25,-5)}
local DoorCloseGoals32 = {Position = Vector3.new(-3.05,37.25,-5)}

local TweenDoor1 = TweenService:Create(Door11, DoorOpenTweenfo, DoorGoals11)
local TweenDoor12 = TweenService:Create(Door12, DoorOpenTweenfo, DoorGoals12)
local TweenDoor2 = TweenService:Create(Door21, DoorOpenTweenfo, DoorGoals21)
local TweenDoor22 = TweenService:Create(Door22, DoorOpenTweenfo, DoorGoals22)
local TweenDoor3 = TweenService:Create(Door31, DoorOpenTweenfo, DoorGoals31)
local TweenDoor32 = TweenService:Create(Door32, DoorOpenTweenfo, DoorGoals32)

local TweenCloseDoor1 = TweenService:Create(Door11, DoorOpenTweenfo, DoorCloseGoals11)
local TweenCloseDoor12 = TweenService:Create(Door12, DoorOpenTweenfo, DoorCloseGoals12)
local TweenCloseDoor2 = TweenService:Create(Door21, DoorOpenTweenfo, DoorCloseGoals21)
local TweenCloseDoor22 = TweenService:Create(Door22, DoorOpenTweenfo, DoorCloseGoals22)
local TweenCloseDoor3 = TweenService:Create(Door31, DoorOpenTweenfo, DoorCloseGoals31)
local TweenCloseDoor32 = TweenService:Create(Door32, DoorOpenTweenfo, DoorCloseGoals32)

local TweenCloseDoor = {{TweenCloseDoor1, TweenCloseDoor12},{TweenCloseDoor2, TweenCloseDoor22},{TweenCloseDoor3, TweenCloseDoor32}}
local TweenDoor = {{TweenDoor1, TweenDoor12},{TweenDoor2, TweenDoor22},{TweenDoor3, TweenDoor32}}

local function CloseDoors(Door)
    for _,Door in pairs(TweenCloseDoor) do
	Door[1]:Play()
	Door[2]:Play()
	end
end

local function OpenDoor(Door)
	Door[1]:Play()
	Door[2]:Play()
end

function OpenDoors()
    for _,Door in pairs(TweenDoor) do
        OpenDoor(Door)
    end
end

CD1.MouseClick:Connect(function()
	CloseDoors()
	wait(2)
	TweenLift1:Play()
	TweenLift1.Completed:Connect(function()
        	OpenDoor(TweenDoor[1])
	end)
end)

CD2.MouseClick:Connect(function()
	CloseDoors()
	wait(2)
	TweenLift2:Play()
	TweenLift2.Completed:Connect(function()
        	OpenDoor(TweenDoor[2])
	end)
end)

CD3.MouseClick:Connect(function()
	CloseDoors()
	wait(2)
	TweenLift3:Play()
	TweenLift3.Completed:Connect(function()
        	OpenDoor(TweenDoor[3])
	end)
end)

Yes, WeldConstraints will only move connected parts when CFrame is updated, otherwise it will move only the part you positioned. More information on WeldConstraint behaviour with regards to CFrame and Position can be found here: WeldConstraint | Documentation - Roblox Creator Hub

1 Like

I added this on the end of my script. It still doesn’t work. Do I have to completely incorporate the model into the tweening?

local LiftChild = LiftGroup:GetChildren()

local NewThread = coroutine.create(function()
	while true do
	LiftChild.CFrame = CFrame.new(Lift.Position)
	end
end)

coroutine.resume(NewThread)

Although I think this still wouldn’t work the way I want, I wanted to see whether this general type of thing would work.

If you tween the original Lift part with CFrame i.e.

local Goals1 = 
{
	CFrame = CFrame.new(0,0,0)
}

Then the parts welded to it should move along without having to directly update their positions

1 Like

Yeah, my understanding of CFrames vs Vector3s was extremely flawed. Thanks for the help, it runs perfectly now.

I didn’t know weld constraints moved the parts if only the CFrame changes. That helps so much and i was wondering for so long why the welded parts won’t move with the anchor. Thx even though you didnt write this for me xD