Help with lift doors

I’m making a lift with 3 floors and a button for each. The lift has two sets of doors, an inside set and an outside set. The inside set is attached to the lift, whereas the outside set is not. The rest of the lift works well, but the inside doors don’t move when they’re supposed to (when the player presses the button). I’ve attached the relevant code although I’ll leave a link to the entire script too.

-- Rest of script for outside doors and lift which works fine.
-- There is also a script which welds the inside doors to the rest of the lift.

local InDoorGoals1 = {CFrame = Lift.CFrame*CFrame.new(-7.71,5.8,-5.5)}
local InDoorGoals2 = {CFrame = Lift.CFrame*CFrame.new(7.71,5.8,-5.5)}

local InDoorCloseGoals1 = {CFrame = Lift.CFrame*CFrame.new(-2.71,5.8,-5.5)}
local InDoorCloseGoals2 = {CFrame = Lift.CFrame*CFrame.new(2.71,5.8,-5.5)}

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

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


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

local function InDoors()
TweenIndoor1:Play()
TweenIndoor2:Play()
end

CD1.MouseClick:Connect(function()
    CloseDoors() -- (Outside doors)
    wait()
    CloseInDoors() -- (Inside doors)
    wait(2)
    TweenLift1:Play()
    TweenLift1.Completed:Connect(function()
            InDoors()
            wait()
            OpenDoor(TweenDoor[1])
    end)
end)

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

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

Video showing the problem (the grey doors should open at each stop):

The whole script (ignore the comments): Paste code - paste.org

4 Likes

Is the Dark Grey Block Door is another part? If yes, you need to set the Tween to the grey block door part so it can open. It seems like the light grey door is moving, but the one in front is not. Add another tween with the front dark door part.

The code I provided is only for the dark grey doors, or ‘inner doors’. The full code is in the link, which shows the code for the rest of the lift, including the outer light grey doors.

I’m assuming the inner doors are not anchored, which allows the lift tween to play and move the welded parts along also.
If thats so, you might want to look into the behavior of welded parts, tween service, and anchored parts. I did some testing real quick and found that the behavior was a bit different from what I expected.

2 Likes

Yeah, it’s probably because the child (doors) isn’t anchored. How would I go about making the doors move then, whilst still making sure they move with the lift?

You could break the welds from the inner doors to the lift root part, anchor the inner door, then play the tween. When you need to move the whole lift, just re weld them to the root part, and un anchor them.

1 Like

Seems fairly excessive, but I’ll try it. There must be an easier way of moving welded parts.

It works ok, the only problem is that I don’t know how to make the doors move relative to the lift.

local InDoorGoals1 = {CFrame = Lift.CFrame*CFrame.new(-7.51,5.8,-5.5)}
local InDoorGoals2 = {CFrame = Lift.CFrame*CFrame.new(7.51,5.8,-5.5)}

local InDoorCloseGoals1 = {CFrame = Lift.CFrame*CFrame.new(-2.71,5.8,-5.5)}
local InDoorCloseGoals2 = {CFrame = Lift.CFrame*CFrame.new(2.71,5.8,-5.5)}

You probably want to create a debounce value (just a true or false book value) which when true you lock the other buttons (commonly done with an if then statement)
Example

if debounce == false then 
   debounce = true
   -- rest of code + wait()
   debounce = false
end
1 Like

Could you expand on this? Thanks.

But won’t the door1.Position be updated as the Door1OpenPos, so then when you call the lift again the doors will just get further apart? I’ve never heard of z-clashing, could you explain? Thanks again.

I did this and it gave me an error:
15:33:30.771 - Unable to cast to Dictionary

15:33:30.772 - Stack Begin

15:33:30.773 - Script ‘Workspace.LiftGroup.Lift.Script’, Line 227

15:33:30.773 - Stack End

The functions moving the lift and the new goals for the inner doors:


local InDoor1Pos = InDoor1.Position
local InDoor2Pos = InDoor2.Position

local InDoorGoals1 = {Position = Vector3.new(InDoor1.Position.X-InDoor1.Size.X-.001, InDoor1.Position.Y, InDoor1.Position.Z)}
local InDoorGoals2 = {Position = Vector3.new(InDoor1.Position.X-InDoor1.Size.X-.001, InDoor1.Position.Y, InDoor1.Position.Z)}

local InDoorCloseGoals1 = {InDoor1Pos}
local InDoorCloseGoals2 = {InDoor2Pos}

CD1.MouseClick:Connect(function()
	CloseDoors()
	wait()
	local TweenCloseIndoor1 = TweenService:Create(InDoor1, DoorOpenTweenfo, InDoorCloseGoals1)
	local TweenCloseIndoor2 = TweenService:Create(InDoor2, DoorOpenTweenfo, InDoorCloseGoals2)

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

		for _, InDoor in pairs (InDoors) do
			local WeldConstraint = Instance.new("WeldConstraint")
				WeldConstraint.Part0 = InDoor
				WeldConstraint.Part1 = Lift
				WeldConstraint.Parent = WeldConstraint.Part0

				InDoor.Anchored = false
		end
	end
	wait(2)
        TweenLift1:Play()
	TweenLift1.Completed:Connect(function()
			local TweenIndoor1 = TweenService:Create(InDoor1, DoorOpenTweenfo, InDoorGoals1)
			local TweenIndoor2 = TweenService:Create(InDoor2, DoorOpenTweenfo, InDoorGoals2)

		function OpenInDoors(InDoor)
			for _,InDoor in pairs (InDoors) do
			InDoor:WaitForChild("WeldConstraint"):Destroy()

			InDoor.Anchored = true
			end

			TweenIndoor1:Play()
			TweenIndoor2:Play()
		end
			wait()
        	OpenDoor(TweenDoor[1])
	end)
end)

CD2.MouseClick:Connect(function()
	CloseDoors()
	wait()
	local TweenCloseIndoor1 = TweenService:Create(InDoor1, DoorOpenTweenfo, InDoorCloseGoals1)
	local TweenCloseIndoor2 = TweenService:Create(InDoor2, DoorOpenTweenfo, InDoorCloseGoals2)

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

		for _, InDoor in pairs (InDoors) do
			local WeldConstraint = Instance.new("WeldConstraint")
				WeldConstraint.Part0 = InDoor
				WeldConstraint.Part1 = Lift
				WeldConstraint.Parent = WeldConstraint.Part0

				InDoor.Anchored = false
		end
	end
	wait(2)
	TweenLift2:Play()
	TweenLift2.Completed:Connect(function()
			local TweenIndoor1 = TweenService:Create(InDoor1, DoorOpenTweenfo, InDoorGoals1)
			local TweenIndoor2 = TweenService:Create(InDoor2, DoorOpenTweenfo, InDoorGoals2)
		function OpenInDoors(InDoor)
			for _,InDoor in pairs (InDoors) do
			InDoor:WaitForChild("WeldConstraint"):Destroy()

			InDoor.Anchored = true
			end

			TweenIndoor1:Play()
			TweenIndoor2:Play()
		end
			wait()
        	OpenDoor(TweenDoor[2])
	end)
end)

CD3.MouseClick:Connect(function()
	CloseDoors()
	wait()
	local TweenCloseIndoor1 = TweenService:Create(InDoor1, DoorOpenTweenfo, InDoorCloseGoals1)
	local TweenCloseIndoor2 = TweenService:Create(InDoor2, DoorOpenTweenfo, InDoorCloseGoals2)

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

		for _, InDoor in pairs (InDoors) do
			local WeldConstraint = Instance.new("WeldConstraint")
				WeldConstraint.Part0 = InDoor
				WeldConstraint.Part1 = Lift
				WeldConstraint.Parent = WeldConstraint.Part0

				InDoor.Anchored = false
		end
	end
	wait(2)
        TweenLift3:Play()
	TweenLift3.Completed:Connect(function()
			local TweenIndoor1 = TweenService:Create(InDoor1, DoorOpenTweenfo, InDoorGoals1)
			local TweenIndoor2 = TweenService:Create(InDoor2, DoorOpenTweenfo, InDoorGoals2)

		function OpenInDoors(InDoor)
			for _,InDoor in pairs (InDoors) do
			InDoor:WaitForChild("WeldConstraint"):Destroy()

			InDoor.Anchored = true
			end

			TweenIndoor1:Play()
			TweenIndoor2:Play()
		end
			wait()
        	OpenDoor(TweenDoor[3])
	end)
end)

(this is not all the code, just the code related to the inner doors)

Oh yeah, completely missed that. Thanks. Although even with that correction it doesn’t work. Instead the doors move with the lift as they should, but don’t open.

I made an elevator, it was one of my gave up project.(It took me a lot of time, and it was not easy to make)
So, here it is. Please study how it works.
Also, you can adjust the height of each floor without breaking it.
It is actually REALLY an advance one for me.

Also, you need to make inside door anchored to tween them in the right place. Or they are not going to move.

Thanks for the reply, I’ll take a look. The inside door is initially welded to the lift itself, which means it must be unanchored. When I need it to move the weld is destroyed and the inner doors are anchored. After this they are rewarded and unanchored again.

Just anchored it during stop. It would work.
And unanchor it when it is going to another floor.

That’s what I’m doing.

CD2.MouseClick:Connect(function()
	CloseDoors()
	wait()
	local TweenCloseIndoor1 = TweenService:Create(InDoor1, DoorOpenTweenfo, InDoorCloseGoals1)
	local TweenCloseIndoor2 = TweenService:Create(InDoor2, DoorOpenTweenfo, InDoorCloseGoals2)

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

		for _, InDoor in pairs (InDoors) do
			local WeldConstraint = Instance.new("WeldConstraint")
				WeldConstraint.Part0 = InDoor
				WeldConstraint.Part1 = Lift
				WeldConstraint.Parent = WeldConstraint.Part0

				InDoor.Anchored = false --unanchored
		end
	end
	wait(2)
        TweenLift2:Play()
	TweenLift2.Completed:Connect(function()
			local TweenIndoor1 = TweenService:Create(InDoor1, DoorOpenTweenfo, InDoorGoals1)
			local TweenIndoor2 = TweenService:Create(InDoor2, DoorOpenTweenfo, InDoorGoals2)
		function OpenInDoors(InDoor)
			for _,InDoor in pairs (InDoors) do
			InDoor:WaitForChild("WeldConstraint"):Destroy()

			InDoor.Anchored = true --anchored
			end

			TweenIndoor1:Play()
			TweenIndoor2:Play()
		end
			wait()
        	OpenDoor(TweenDoor[2])
	end)
end)