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