Elevator Doors Not Opening Once Floor Is Reached

may or may not be a dumb problem, but I just can’t get it to open once the floor is reached

Script:

local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.RemoteEvents
local LDoor = script.Parent.DoorLeft
local RDoor = script.Parent.DoorRight
local elevator = game.Workspace.Elevator
local prompt = script.Parent.Panel.FirstFloor.Button.PickupAttachment.ProximityPrompt

local OPENING_TIME = 1.5
local CLOSING_TIME = 2.5
local CLOSING_DELAY = 2.5
local floorOne = game.Workspace.DebrisFolder.FloorOne
local moveSpeed = 2 --the smaller the number is, the slower it moves
local promptTriggered = false
local isMoving = false

local floorOneReached = false
local floorTwoReached = false
local floorThreeReached = false

prompt.Enabled = false

local Opening = TweenInfo.new(OPENING_TIME, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local Closing = TweenInfo.new(CLOSING_TIME, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

local LOpen = TweenService:Create(LDoor, Opening, {CFrame = LDoor.CFrame * CFrame.new(0, 0, -3.3)})
local LClose = TweenService:Create(LDoor, Closing, {CFrame = LDoor.CFrame * CFrame.new(0, 0, 0)})
local ROpen = TweenService:Create(RDoor, Opening, {CFrame = RDoor.CFrame * CFrame.new(0, 0, -3.3)})
local RClose = TweenService:Create(RDoor, Closing, {CFrame = RDoor.CFrame * CFrame.new(0, 0, 0)})

local elevatorParts = {}
for _, part in ipairs(elevator:GetDescendants()) do
	if part:IsA("BasePart") then
		table.insert(elevatorParts, part)
	end
end

local function moveElevatorDown(targetPart)
	if isMoving then
		return
	end
	if floorOne == nil then
		return
	end
	isMoving = true

	local startPos = elevator.PrimaryPart.CFrame
	local endPos = targetPart.CFrame
	if endPos.Y >= startPos.Y then 
		isMoving = false
		return
	end
	local distance = (endPos.Position - startPos.Position).Magnitude

	local movingTime = distance / moveSpeed

	local tweens = {}
	for _, part in ipairs(elevatorParts) do
		local partTween = TweenService:Create(part, TweenInfo.new(movingTime, Enum.EasingStyle.Quad), {CFrame = part.CFrame * CFrame.new(0, -distance, 0)})
		table.insert(tweens, partTween)
	end

	for _, tween in ipairs(tweens) do
		tween:Play()
	end

	for _, tween in ipairs(tweens) do
		tween.Completed:Wait()
		isMoving = false
	end

	if isMoving == false and elevator.PrimaryPart.Position.Y <= targetPart.Position.Y then
		LOpen:Play()
		ROpen:Play()
	end
end

Remotes.ElevatorDoorsOpen.OnServerEvent:Connect(function(player)
	ROpen:Play()
	LOpen:Play()
end)

Remotes.ElevatorDoorsClose.OnServerEvent:Connect(function(player)
	task.wait(CLOSING_DELAY)
	LClose:Play()
	RClose:Play()
	task.wait(2)
	prompt.Enabled = true
end)


prompt.Triggered:Connect(function()
	moveElevatorDown(floorOne)
end)

Snippet of the code that isn’t working:

	if isMoving == false and elevator.PrimaryPart.Position.Y <= targetPart.Position.Y then
		LOpen:Play()
		ROpen:Play()
	end

The elevator doors open and close once the event is fired, but not when the elevator has reached the floor

1 Like

Seems like you wouldn’t need the if statement here since you waited for all the tweens to finish. It could be very possible that the Y position has little fractional differences and thereby not triggering the AND part of this statement. JUst try the LOpen:Play() and ROpen:Play() and see what happens.

same issue… It’s still not opening the doors

Here try to replace this:

	for _, tween in ipairs(tweens) do
		tween.Completed:Wait()
	    isMoving = false
	end

with this:

	tweens[1].Completed:Wait()
	isMoving = false

You should only need to wait on 1 tween since they are all the same timing and such.

well, it sorta works now :sweat_smile:
the tween is kinda broken but I think I can fix it.
Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.