Lift Inner Doors CFrame Help

I’m making a lift as a project to improve my scripting skills. The lift actually works pretty well, apart from the inner doors. They are attached to the lift and as such should follow the lift, and move at the same position as the lift. I tried using coroutines to constantly update the variable of the lift position but this hasn’t helped the situation.

The relevant code:

local LiftPos = Lift.Position

local newThread = coroutine.create(function()
	while wait() do
		LiftPos = Lift.Position
	end
end)

coroutine.resume(newThread)

local InDoorGoals1 = {Position = Vector3.new(LiftPos.X-InDoor1.Size.X-2.711, LiftPos.Y+5.8, LiftPos.Z-5.5)}
local InDoorGoals2 = {Position = Vector3.new(LiftPos.X+InDoor1.Size.X+2.711, LiftPos.Y+5.8, LiftPos.Z-5.5)}

local InDoorCloseGoals1 = {Position = Vector3.new(LiftPos.X-2.71, LiftPos.Y+5.8, LiftPos.Z-5.5)}
local InDoorCloseGoals2 = {Position = Vector3.new(LiftPos.X+2.71, LiftPos.Y+5.8, LiftPos.Z-5.5)}

local TweenCloseIndoor1 = TweenService:Create(InDoor1, DoorOpenTweenfo, InDoorCloseGoals1)
local TweenCloseIndoor2 = TweenService:Create(InDoor2, DoorOpenTweenfo, InDoorCloseGoals2)

local TweenIndoor1 = TweenService:Create(InDoor1, DoorOpenTweenfo, InDoorGoals1)
local TweenIndoor2 = TweenService:Create(InDoor2, DoorOpenTweenfo, InDoorGoals2)

local function OpenInDoors(InDoor)		
	TweenIndoor1:Play()
	TweenIndoor2:Play()
end

local function CloseInDoors(InDoor)
	TweenCloseIndoor1:Play()
	TweenCloseIndoor2:Play()
end

There is a lot more code than this, so if you want context here is the entire script:

Video of the issue:

By creating the tweens at the start of the code, you’re not left with much flexibility. You can define the offset for each door, such as local offset1 = Vector3.new(-2.71, 5.8, -5.5), and create a new tween each time you open/close the doors.

local offset1 = Vector3.new(-2.71, 0, 0) -- position relative to the door's current position.
local offset2 = Vector3.new(2.71, 0, 0)

local function OpenInDoors(InDoor)		
	TweenService:Create(InDoor1, DoorOpenTweenfo, {Position = InDoor1.Position + offset1}):Play()
	TweenService:Create(InDoor2, DoorOpenTweenfo, {Position = InDoor2.Position + offset2}):Play()
end

-- for close doors, just subtract the offset instead
1 Like

Thanks for the reply. Would I need the coroutine at all if I created the tween as you have done? In my actual code I go onto call the function ‘OpenInDoors’ in another function, would it be better if I created these tweens in the final function?

I don’t think the coroutine would be necessary. You should create these tweens inside of the open/close functions, and they will move based on the most recent positions.

1 Like

So the position will be updated whenever the function is called?