I’ve been working on an elevator system for someone and I’ve come across a pretty big problem. My elevator can go up floors just fine, but it can not go down to any floors except floor 1. Here’s my script for the 1st floor button and any floors above it
1st floor
-- Floor list. For every floor you make, place a part that is the same size as the elevator floor and has the same cordinates except for the y cordinate. Ex: If the elevator floor's position is 0(0,0,0) then the new cordinates would be (0,5,0) to make it directly above the floor
-- Ex: local floor2 = game.Workspace.Floor2Position.Position
local Floor1Pos = game.Workspace.FL1cords.Position
local Floor2Pos = game.Workspace.FL2cords.Position
local Floor3Pos = game.Workspace.FL3cords.Position
local Floor4Pos = game.Workspace.FL4cords.Position
local Floor5Pos = game.Workspace.FL5cords.Position
-- End of list but can be extended for every floor
local function elevator()
if FloorNumber.Value == 1 then -- Change the "1" to whatever floor the button goes to. Ex: If the button goes to floor 2, then change the "1" to 2
print("Didn't change floors due to the elevator already being on the selected floor.")
elseif
FloorNumber.Value > 1 then
FloorNumber.Value = 1
while true do
local elevatorFloorPos = elevatorFloor.Position
elevatorFloor.CFrame = CFrame.new(elevatorFloor.Position - Vector3.new(0,0.5,0)) -- You can change the Y cordinate to change how fast the elevator moves (higher the faster). DO NOT change the X or Z values
wait()
if elevatorFloorPos == Floor1Pos then
break
end
end
end
end
ClickDetector.MouseClick:Connect(elevator)
Floors above floor 1
-- Floor list. For every floor you make, place a part that is the same size as the elevator floor and has the same cordinates except for the y cordinate. Ex: If the elevator floor's position is 0(0,0,0) then the new cordinates would be (0,5,0) to make it directly above the floor
-- Ex: local floor2 = game.Workspace.Floor2Position.Position
local Floor1Pos = game.Workspace.FL1cords.Position
local Floor2Pos = game.Workspace.FL2cords.Position
local Floor3Pos = game.Workspace.FL3cords.Position
local Floor4Pos = game.Workspace.FL4cords.Position
local Floor5Pos = game.Workspace.FL5cords.Position
--End of list but can be extended for every floor
local function elevator()
if FloorNumber.Value == 3 then -- Change the "1" to whatever floor the button goes to. Ex: If the button goes to floor 2, then change the "1" to 2
-- If the elevator is already on the designated floor
print("Didn't change floors due to the elevator already being on the selected floor.")
elseif
FloorNumber.Value < 3 then -- If elevator is below designated floor
FloorNumber.Value = 3
while true do
local elevatorPos = elevatorFloor.Position -- COPY THIS TO BOTH SCRIPTS THAT MAKE THE ELEVATOR GO DOWN AND UP
elevatorFloor.CFrame = CFrame.new(elevatorFloor.Position + Vector3.new(0,0.5,0))
wait()
if elevatorPos == Floor3Pos then -- Switch the Floor pos variable to whatever floor the button correct. MAKE SURE THAT THIS LINE OF CODE IS COPIED FOR THE SCRIPTS THAT MAKE THE ELEVATOR GO DOWN AND UP. Change variable to whatever floor position you need.
break
else
if FloorNumber.Value > 3 then -- If elevator is above designated floor
FloorNumber.Value = 3
while true do
local elevatorPos = elevatorFloor.Position
elevatorFloor.CFrame = CFrame.new(elevatorFloor.Position - Vector3.new(0,0.5,0))
wait()
if elevatorPos == Floor3Pos then
break
end
end
end
Anyone know why the elevator simply doesn’t go down to any floors except 1?
Edit: Cleaned some stuff up