Advertisement
HowToRoblox

ElevatorServer

Nov 11th, 2022 (edited)
2,779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.98 KB | None | 0 0
  1. local tweenService = game:GetService("TweenService")
  2.  
  3. local speed = 3
  4. local openDoorTime = 2
  5. local closeDoorTime = 2
  6.  
  7. local elevator = script.Parent
  8.  
  9. local floors = elevator:WaitForChild("FloorPositions")
  10. local floorButtons = elevator:WaitForChild("FloorButtons")
  11. local floorDoors = elevator:WaitForChild("FloorDoors")
  12.  
  13. local carriage = elevator:WaitForChild("Carriage")
  14. local carriageDoors = carriage:WaitForChild("Door")
  15. local carriageButtons = carriage:WaitForChild("Buttons")
  16. local carriageDoorButtons = carriageButtons:WaitForChild("DoorButtons")
  17. local carriageFloorButtons = carriageButtons:WaitForChild("FloorButtons")
  18. local carriageCurrentFloor = carriageButtons:WaitForChild("CurrentFloor")
  19.  
  20. local soundContainer = carriage.SoundContainer
  21. local dingSound = soundContainer:FindFirstChild("Ding")
  22. local doorOpenSound = soundContainer:FindFirstChild("DoorOpen")
  23. local doorCloseSound = soundContainer:FindFirstChild("DoorClose")
  24. local goingDownSound = soundContainer:FindFirstChild("GoingDown")
  25. local goingUpSound = soundContainer:FindFirstChild("GoingUp")
  26. local movingSound = soundContainer:FindFirstChild("Moving")
  27. local musicSound = soundContainer:FindFirstChild("Music")
  28.  
  29.  
  30. local floorQueue = {}
  31.  
  32. local currentFloor = 1
  33. local goalFloor = 1
  34.  
  35. local carriageDoorDebounce = false
  36.  
  37.  
  38. function tween(cframeValue, goalCFrame, duration)
  39.    
  40.     if cframeValue and goalCFrame and not cframeValue:FindFirstChild("CURRENTLY TWEENING") then
  41.        
  42.         local tweeningValue = Instance.new("StringValue")
  43.         tweeningValue.Name = "CURRENTLY TWEENING"
  44.         tweeningValue.Parent = cframeValue
  45.        
  46.         local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
  47.         local newTween = tweenService:Create(cframeValue, tweenInfo, {Value = goalCFrame})
  48.        
  49.         newTween:Play()
  50.         newTween.Completed:Wait()
  51.        
  52.         tweeningValue:Destroy()
  53.     end
  54. end
  55.  
  56.  
  57. local floorPositions = {}
  58.  
  59. for i = 1, #floors:GetChildren() do
  60.     table.insert(floorPositions, floors[i].CFrame)
  61. end
  62.  
  63. carriage:SetPrimaryPartCFrame(floorPositions[currentFloor])
  64.  
  65.  
  66. --BUTTONS FOR CALLING ELEVATOR TO A FLOOR
  67. for i, floorButton in pairs(floorButtons:GetChildren()) do
  68.    
  69.     local floorNumber = tonumber(floorButton.Name)
  70.    
  71.     local callButton = floorButton.CallButton
  72.     callButton.Light.Material = Enum.Material.Metal
  73.    
  74.     local clickDetector = Instance.new("ClickDetector")
  75.     clickDetector.MaxActivationDistance = 10
  76.     clickDetector.Parent = callButton
  77.    
  78.     clickDetector.MouseClick:Connect(function(plr)
  79.        
  80.         if not table.find(floorQueue, floorNumber) then
  81.             table.insert(floorQueue, floorNumber)
  82.            
  83.             callButton.Light.Material = Enum.Material.Neon
  84.            
  85.             while table.find(floorQueue, floorNumber) do
  86.                 task.wait(0.5)
  87.             end
  88.             callButton.Light.Material = Enum.Material.Metal
  89.         end
  90.     end)
  91.    
  92.     local currentFloorUI = floorButton.CurrentFloor.CurrentFloorGui.CurrentFloorFrame
  93.    
  94.     task.spawn(function()
  95.         while true do
  96.             task.wait(0.3)
  97.            
  98.             currentFloorUI.CurrentFloorText.Text = currentFloor
  99.            
  100.             if goalFloor > currentFloor then
  101.                 currentFloorUI.GoingDown.Visible = false
  102.                 currentFloorUI.GoingUp.Visible = true
  103.                
  104.             elseif goalFloor < currentFloor then
  105.                 currentFloorUI.GoingUp.Visible = false
  106.                 currentFloorUI.GoingDown.Visible = true
  107.                
  108.             else
  109.                 currentFloorUI.GoingDown.Visible = false
  110.                 currentFloorUI.GoingUp.Visible = false
  111.             end
  112.         end
  113.     end)
  114. end
  115.  
  116.  
  117. --SET UP FLOOR DOORS
  118. for i, floorDoor in pairs(floorDoors:GetChildren()) do
  119.    
  120.     local floorNumber = tonumber(floorDoor.Name)
  121.    
  122.     local leftDoor = floorDoor.LeftDoor
  123.     local leftDoorCFrame = leftDoor.PrimaryPart.CFrame
  124.    
  125.     local cframeValueLeft = Instance.new("CFrameValue")
  126.     cframeValueLeft.Name = "CFrameValue"
  127.     cframeValueLeft.Value = CFrame.new()
  128.     cframeValueLeft.Parent = leftDoor
  129.    
  130.     if floorNumber == currentFloor then
  131.         cframeValueLeft.Value = CFrame.new(leftDoor.PrimaryPart.Size.X * leftDoor.PrimaryPart.CFrame.RightVector)
  132.     end
  133.     leftDoor:SetPrimaryPartCFrame(leftDoorCFrame * cframeValueLeft.Value)
  134.    
  135.     cframeValueLeft:GetPropertyChangedSignal("Value"):Connect(function()
  136.         leftDoor:SetPrimaryPartCFrame(leftDoorCFrame * cframeValueLeft.Value)
  137.     end)
  138.    
  139.     local rightDoor = floorDoor.RightDoor
  140.     local rightDoorCFrame = rightDoor.PrimaryPart.CFrame
  141.  
  142.     local cframeValueRight = Instance.new("CFrameValue")
  143.     cframeValueRight.Name = "CFrameValue"
  144.     cframeValueRight.Value = CFrame.new()
  145.     cframeValueRight.Parent = rightDoor
  146.    
  147.     if floorNumber == currentFloor then
  148.         cframeValueRight.Value = CFrame.new(rightDoor.PrimaryPart.Size.X * -rightDoor.PrimaryPart.CFrame.RightVector)
  149.     end
  150.     rightDoor:SetPrimaryPartCFrame(rightDoorCFrame * cframeValueRight.Value)
  151.  
  152.     cframeValueRight:GetPropertyChangedSignal("Value"):Connect(function()
  153.         rightDoor:SetPrimaryPartCFrame(rightDoorCFrame * cframeValueRight.Value)
  154.     end)
  155. end
  156.  
  157.  
  158. --SET UP ELEVATOR BUTTONS
  159. for i, floorButton in pairs(carriageFloorButtons:GetChildren()) do
  160.    
  161.     local floorNumber = tonumber(floorButton.Name)
  162.    
  163.     floorButton.Light.Material = Enum.Material.Metal
  164.    
  165.     local clickDetector = Instance.new("ClickDetector")
  166.     clickDetector.MaxActivationDistance = 10
  167.     clickDetector.Parent = floorButton
  168.    
  169.     clickDetector.MouseClick:Connect(function(plr)
  170.        
  171.         if not table.find(floorQueue, floorNumber) and currentFloor ~= floorNumber then
  172.             table.insert(floorQueue, floorNumber)
  173.  
  174.             floorButton.Light.Material = Enum.Material.Neon
  175.  
  176.             while table.find(floorQueue, floorNumber) do
  177.                 task.wait(0.5)
  178.             end
  179.             floorButton.Light.Material = Enum.Material.Metal
  180.         end
  181.     end)
  182.    
  183.     local buttonGui = Instance.new("SurfaceGui")
  184.     buttonGui.Face = Enum.NormalId.Right
  185.     buttonGui.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
  186.     buttonGui.PixelsPerStud = 300
  187.     local buttonText = Instance.new("TextLabel")
  188.     buttonText.BackgroundTransparency = 1
  189.     buttonText.Font = Enum.Font.RobotoCondensed
  190.     buttonText.FontFace.Weight = Enum.FontWeight.Bold
  191.     buttonText.TextScaled = true
  192.     buttonText.TextColor3 = Color3.fromRGB(163, 168, 185)
  193.     buttonText.AnchorPoint = Vector2.new(0.5, 0.5)
  194.     buttonText.Position = UDim2.new(0.5, 0, 0.5, 0)
  195.     buttonText.Size = UDim2.new(0.7, 0, 0.7, 0)
  196.     buttonText.Text = floorNumber
  197.     buttonText.Parent = buttonGui
  198.     buttonGui.Parent = floorButton
  199. end
  200.  
  201.  
  202. --SET UP ELEVATOR DOORS
  203. local carriageLeftDoor = carriageDoors.LeftDoor
  204.  
  205. local carriageLeftDoorCFrame = carriageLeftDoor.PrimaryPart.CFrame
  206.  
  207. local cframeValueLeft = Instance.new("CFrameValue")
  208. cframeValueLeft.Name = "CFrameValue"
  209. cframeValueLeft.Value = CFrame.new(carriageLeftDoor.PrimaryPart.Size.X * carriageLeftDoor.PrimaryPart.CFrame.RightVector)
  210. cframeValueLeft.Parent = carriageLeftDoor
  211.  
  212. local leftDoorOffset = carriageLeftDoor.PrimaryPart.Position - carriage.PrimaryPart.Position
  213.  
  214. carriageLeftDoor:SetPrimaryPartCFrame(carriageLeftDoorCFrame * cframeValueLeft.Value)
  215. cframeValueLeft:GetPropertyChangedSignal("Value"):Connect(function()
  216.     carriageLeftDoor:SetPrimaryPartCFrame((carriage.PrimaryPart.CFrame + leftDoorOffset) * cframeValueLeft.Value)
  217. end)
  218.  
  219.  
  220. local carriageRightDoor = carriageDoors.RightDoor
  221.  
  222. local carriageRightDoorCFrame = carriageRightDoor.PrimaryPart.CFrame
  223.  
  224. local cframeValueRight = Instance.new("CFrameValue")
  225. cframeValueRight.Name = "CFrameValue"
  226. cframeValueRight.Value = CFrame.new(carriageRightDoor.PrimaryPart.Size.X * -carriageRightDoor.PrimaryPart.CFrame.RightVector)
  227. cframeValueRight.Parent = carriageRightDoor
  228.  
  229. local rightDoorOffset = carriageRightDoor.PrimaryPart.Position - carriage.PrimaryPart.Position
  230.  
  231. carriageRightDoor:SetPrimaryPartCFrame(carriageRightDoorCFrame * cframeValueRight.Value)
  232. cframeValueRight:GetPropertyChangedSignal("Value"):Connect(function()
  233.     carriageRightDoor:SetPrimaryPartCFrame((carriage.PrimaryPart.CFrame + rightDoorOffset) * cframeValueRight.Value)
  234. end)
  235.  
  236.  
  237. --SET UP ELEVATOR OPEN DOOR BUTTON
  238. local carriageOpenDoorButton = carriageDoorButtons.OpenDoor
  239. carriageOpenDoorButton.Light.Material = Enum.Material.Metal
  240.  
  241. local openClickDetector = Instance.new("ClickDetector")
  242. openClickDetector.MaxActivationDistance = 10
  243. openClickDetector.Parent = carriageOpenDoorButton
  244.  
  245.  
  246. openClickDetector.MouseClick:Connect(function(plr)
  247.    
  248.     local currentFloorDoors = floorDoors[currentFloor]
  249.     local currentLeftDoor = currentFloorDoors.LeftDoor
  250.     local currentRightDoor = currentFloorDoors.RightDoor
  251.    
  252.     local isOpen = currentLeftDoor.CFrameValue.Value.Position.Magnitude > 0 or currentRightDoor.CFrameValue.Value.Position.Magnitude > 0
  253.  
  254.     if currentFloor == goalFloor and not carriageDoorDebounce and not isOpen then
  255.         carriageDoorDebounce = true
  256.        
  257.         carriageOpenDoorButton.Light.Material = Enum.Material.Neon
  258.        
  259.         local leftGoalCF = CFrame.new(currentLeftDoor.PrimaryPart.Size.X * currentLeftDoor.PrimaryPart.CFrame.RightVector)
  260.         local rightGoalCF = CFrame.new(currentRightDoor.PrimaryPart.Size.X * -currentRightDoor.PrimaryPart.CFrame.RightVector)
  261.        
  262.         task.spawn(tween, currentLeftDoor.CFrameValue, leftGoalCF, openDoorTime)
  263.         task.spawn(tween, currentRightDoor.CFrameValue, rightGoalCF, openDoorTime)
  264.        
  265.         if doorOpenSound then
  266.             doorOpenSound:Play()
  267.         end
  268.        
  269.         task.wait(0.2)
  270.        
  271.         local leftCarriageDoorGoalCF = CFrame.new(carriageLeftDoor.PrimaryPart.Size.X * carriageLeftDoor.PrimaryPart.CFrame.RightVector)
  272.         local rightCarriageDoorGoalCF = CFrame.new(carriageRightDoor.PrimaryPart.Size.X * -carriageRightDoor.PrimaryPart.CFrame.RightVector)
  273.        
  274.         task.spawn(tween, cframeValueLeft, leftCarriageDoorGoalCF, openDoorTime)
  275.         task.spawn(tween, cframeValueRight, rightCarriageDoorGoalCF, openDoorTime)
  276.  
  277.         task.wait(openDoorTime)
  278.         carriageOpenDoorButton.Light.Material = Enum.Material.Metal
  279.         carriageDoorDebounce = false
  280.     end
  281. end)
  282.  
  283.  
  284. --SET UP ELEVATOR CLOSE DOOR BUTTON
  285. local carriageCloseDoorButton = carriageDoorButtons.CloseDoor
  286. carriageCloseDoorButton.Light.Material = Enum.Material.Metal
  287.  
  288. local closeClickDetector = Instance.new("ClickDetector")
  289. closeClickDetector.MaxActivationDistance = 10
  290. closeClickDetector.Parent = carriageCloseDoorButton
  291.  
  292.  
  293. closeClickDetector.MouseClick:Connect(function(plr)
  294.  
  295.     local currentFloorDoors = floorDoors[currentFloor]
  296.     local currentLeftDoor = currentFloorDoors.LeftDoor
  297.     local currentRightDoor = currentFloorDoors.RightDoor
  298.  
  299.     local isOpen = cframeValueLeft.Value.Position.Magnitude > 0 or cframeValueRight.Value.Position.Magnitude > 0
  300.  
  301.     if currentFloor == goalFloor and not carriageDoorDebounce and isOpen then
  302.         carriageDoorDebounce = true
  303.  
  304.         carriageCloseDoorButton.Light.Material = Enum.Material.Neon
  305.  
  306.         local emptyCFrame = CFrame.new()
  307.  
  308.         task.spawn(tween, cframeValueLeft, emptyCFrame, closeDoorTime)
  309.         task.spawn(tween, cframeValueRight, emptyCFrame, closeDoorTime)
  310.  
  311.         if doorCloseSound then
  312.             doorCloseSound:Play()
  313.         end
  314.        
  315.         task.wait(0.2)
  316.        
  317.         task.spawn(tween, currentLeftDoor.CFrameValue, emptyCFrame, closeDoorTime)
  318.         task.spawn(tween, currentRightDoor.CFrameValue, emptyCFrame, closeDoorTime)
  319.  
  320.         task.wait(closeDoorTime)
  321.         carriageCloseDoorButton.Light.Material = Enum.Material.Metal
  322.         carriageDoorDebounce = false
  323.     end
  324. end)
  325.  
  326.  
  327. --SET UP ELEVATOR MOVEMENT
  328. local carriageCFV = Instance.new("CFrameValue")
  329. carriageCFV.Name = "CFrameValue"
  330. carriageCFV.Value = carriage.PrimaryPart.CFrame
  331. carriageCFV.Parent = carriage
  332.  
  333. carriageCFV:GetPropertyChangedSignal("Value"):Connect(function()
  334.     carriage:SetPrimaryPartCFrame(carriageCFV.Value)
  335. end)
  336.  
  337.  
  338. --ELEVATOR LOOP
  339. local currentFloorUI = carriageCurrentFloor.CurrentFloorGui.CurrentFloorFrame
  340.  
  341. while true do
  342.     task.wait(0.1)
  343.    
  344.     currentFloorUI.CurrentFloorText.Text = currentFloor
  345.     if goalFloor > currentFloor then
  346.         currentFloorUI.GoingDown.Visible = false
  347.         currentFloorUI.GoingUp.Visible = true
  348.  
  349.     elseif goalFloor < currentFloor then
  350.         currentFloorUI.GoingUp.Visible = false
  351.         currentFloorUI.GoingDown.Visible = true
  352.  
  353.     else
  354.         currentFloorUI.GoingDown.Visible = false
  355.         currentFloorUI.GoingUp.Visible = false
  356.     end
  357.    
  358.     if #floorQueue > 0 then
  359.         goalFloor = floorQueue[1]
  360.        
  361.         if goalFloor ~= currentFloor then  
  362.            
  363.             goalFloor = floorQueue[1]
  364.            
  365.             local goingUp = goalFloor > currentFloor
  366.            
  367.             if goingUp then
  368.                 currentFloorUI.GoingDown.Visible = false
  369.                 currentFloorUI.GoingUp.Visible = true
  370.             else
  371.                 currentFloorUI.GoingUp.Visible = false
  372.                 currentFloorUI.GoingDown.Visible = true
  373.             end
  374.            
  375.            
  376.             local currentFloorDoors = floorDoors[currentFloor]
  377.             local currentLeftDoor = currentFloorDoors.LeftDoor
  378.             local currentRightDoor = currentFloorDoors.RightDoor
  379.  
  380.             local isOpen = cframeValueLeft.Value.Position.Magnitude > 0 or cframeValueRight.Value.Position.Magnitude > 0
  381.  
  382.             if isOpen then
  383.                 while carriageDoorDebounce do
  384.                     task.wait(1)
  385.                 end
  386.                
  387.                 carriageDoorDebounce = true
  388.                
  389.                 carriageCloseDoorButton.Light.Material = Enum.Material.Neon
  390.                
  391.                 local emptyCFrame = CFrame.new()
  392.  
  393.                 task.spawn(tween, cframeValueLeft, emptyCFrame, closeDoorTime)
  394.                 task.spawn(tween, cframeValueRight, emptyCFrame, closeDoorTime)
  395.  
  396.                 if doorCloseSound then
  397.                     doorCloseSound:Play()
  398.                 end
  399.  
  400.                 task.wait(0.2)
  401.  
  402.                 task.spawn(tween, currentLeftDoor.CFrameValue, emptyCFrame, closeDoorTime)
  403.                 task.spawn(tween, currentRightDoor.CFrameValue, emptyCFrame, closeDoorTime)
  404.  
  405.                 task.wait(closeDoorTime)
  406.                 carriageCloseDoorButton.Light.Material = Enum.Material.Metal
  407.                 carriageDoorDebounce = false
  408.             end
  409.             cframeValueLeft.Value = CFrame.new()
  410.             cframeValueRight.Value = CFrame.new()
  411.             currentLeftDoor.CFrameValue.Value = CFrame.new()
  412.             currentRightDoor.CFrameValue.Value = CFrame.new()
  413.            
  414.             task.wait(1)
  415.             if goingUp and goingUpSound then
  416.                 goingUpSound:Play()
  417.             elseif not goingUp and goingDownSound then
  418.                 goingDownSound:Play()
  419.             end
  420.            
  421.             task.wait(goingUpSound.TimeLength)
  422.            
  423.             if movingSound then
  424.                 movingSound:Play()
  425.             end
  426.             if musicSound then
  427.                 musicSound:Play()
  428.             end
  429.            
  430.             local startFloor = goingUp and currentFloor + 1 or currentFloor - 1
  431.             local step =  goingUp and 1 or -1
  432.            
  433.             for i = startFloor, goalFloor, step do
  434.                
  435.                 if movingSound and not movingSound.IsPlaying then
  436.                     movingSound:Play()
  437.                 end
  438.                 if musicSound and not musicSound.IsPlaying then
  439.                     musicSound:Play()
  440.                 end
  441.                
  442.                 local floorCFrame = floorPositions[i]
  443.                
  444.                 local distance = (carriage.PrimaryPart.Position - floorCFrame.Position).Magnitude
  445.                 local duration = distance / speed
  446.                
  447.                 tween(carriageCFV, floorCFrame, duration)
  448.                
  449.                 if table.find(floorQueue, i) and i ~= goalFloor then
  450.                     if dingSound then
  451.                         dingSound:Play()
  452.                     end
  453.                    
  454.                     currentFloor = i
  455.                     currentFloorUI.CurrentFloorText.Text = currentFloor
  456.                        
  457.                     task.wait(1)
  458.                        
  459.                     carriageDoorDebounce = true
  460.                    
  461.                     currentFloorDoors = floorDoors[currentFloor]
  462.                     currentLeftDoor = currentFloorDoors.LeftDoor
  463.                     currentRightDoor = currentFloorDoors.RightDoor
  464.                        
  465.                     local leftGoalCF = CFrame.new(currentLeftDoor.PrimaryPart.Size.X * currentLeftDoor.PrimaryPart.CFrame.RightVector)
  466.                     local rightGoalCF = CFrame.new(currentRightDoor.PrimaryPart.Size.X * -currentRightDoor.PrimaryPart.CFrame.RightVector)
  467.  
  468.                     task.spawn(tween, currentLeftDoor.CFrameValue, leftGoalCF, openDoorTime)
  469.                     task.spawn(tween, currentRightDoor.CFrameValue, rightGoalCF, openDoorTime)
  470.  
  471.                     if doorOpenSound then
  472.                         doorOpenSound:Play()
  473.                     end
  474.                    
  475.                     carriageOpenDoorButton.Light.Material = Enum.Material.Neon
  476.  
  477.                     task.wait(0.2)
  478.  
  479.                     local leftCarriageDoorGoalCF = CFrame.new(carriageLeftDoor.PrimaryPart.Size.X * carriageLeftDoor.PrimaryPart.CFrame.RightVector)
  480.                     local rightCarriageDoorGoalCF = CFrame.new(carriageRightDoor.PrimaryPart.Size.X * -carriageRightDoor.PrimaryPart.CFrame.RightVector)
  481.  
  482.                     task.spawn(tween, cframeValueLeft, leftCarriageDoorGoalCF, openDoorTime)
  483.                     task.spawn(tween, cframeValueRight, rightCarriageDoorGoalCF, openDoorTime)
  484.                        
  485.                     task.wait(openDoorTime)
  486.                     carriageDoorDebounce = false
  487.                     carriageOpenDoorButton.Light.Material = Enum.Material.Metal
  488.                    
  489.                    
  490.                     if movingSound then
  491.                         movingSound:Stop()
  492.                     end
  493.                     if musicSound then
  494.                         musicSound:Stop()
  495.                     end
  496.                    
  497.                     table.remove(floorQueue, table.find(floorQueue, i))
  498.                    
  499.                     task.wait(7)
  500.                     while carriageDoorDebounce do
  501.                         task.wait(1)
  502.                     end
  503.                        
  504.                     carriageDoorDebounce = true
  505.                        
  506.                     local emptyCFrame = CFrame.new()
  507.  
  508.                     task.spawn(tween, cframeValueLeft, emptyCFrame, closeDoorTime)
  509.                     task.spawn(tween, cframeValueRight, emptyCFrame, closeDoorTime)
  510.  
  511.                     if doorCloseSound then
  512.                         doorCloseSound:Play()
  513.                     end
  514.  
  515.                     task.wait(0.2)
  516.  
  517.                     task.spawn(tween, currentLeftDoor.CFrameValue, emptyCFrame, closeDoorTime)
  518.                     task.spawn(tween, currentRightDoor.CFrameValue, emptyCFrame, closeDoorTime)
  519.  
  520.                     task.wait(closeDoorTime + 1)
  521.                     carriageDoorDebounce = false
  522.    
  523.                     if goingUp and goingUpSound then
  524.                         goingUpSound:Play()
  525.                     elseif not goingUp and goingDownSound then
  526.                         goingDownSound:Play()
  527.                     end
  528.                    
  529.                     task.wait(goingUpSound.TimeLength)
  530.                 end
  531.                
  532.                
  533.                 currentFloor = i
  534.                 currentFloorUI.CurrentFloorText.Text = currentFloor
  535.             end
  536.            
  537.             if movingSound then
  538.                 movingSound:Stop()
  539.             end
  540.             if musicSound then
  541.                 musicSound:Stop()
  542.             end
  543.        
  544.        
  545.             if dingSound then
  546.                 dingSound:Play()
  547.             end
  548.            
  549.            
  550.             task.wait(1)
  551.  
  552.             carriageDoorDebounce = true
  553.            
  554.             carriageOpenDoorButton.Light.Material = Enum.Material.Neon
  555.            
  556.             local currentFloorDoors = floorDoors[currentFloor]
  557.             local currentLeftDoor = currentFloorDoors.LeftDoor
  558.             local currentRightDoor = currentFloorDoors.RightDoor
  559.  
  560.             local leftGoalCF = CFrame.new(currentLeftDoor.PrimaryPart.Size.X * currentLeftDoor.PrimaryPart.CFrame.RightVector)
  561.             local rightGoalCF = CFrame.new(currentRightDoor.PrimaryPart.Size.X * -currentRightDoor.PrimaryPart.CFrame.RightVector)
  562.  
  563.             task.spawn(tween, currentLeftDoor.CFrameValue, leftGoalCF, openDoorTime)
  564.             task.spawn(tween, currentRightDoor.CFrameValue, rightGoalCF, openDoorTime)
  565.  
  566.             if doorOpenSound then
  567.                 doorOpenSound:Play()
  568.             end
  569.  
  570.             task.wait(0.2)
  571.  
  572.             local leftCarriageDoorGoalCF = CFrame.new(carriageLeftDoor.PrimaryPart.Size.X * carriageLeftDoor.PrimaryPart.CFrame.RightVector)
  573.             local rightCarriageDoorGoalCF = CFrame.new(carriageRightDoor.PrimaryPart.Size.X * -carriageRightDoor.PrimaryPart.CFrame.RightVector)
  574.  
  575.             task.spawn(tween, cframeValueLeft, leftCarriageDoorGoalCF, openDoorTime)
  576.             task.spawn(tween, cframeValueRight, rightCarriageDoorGoalCF, openDoorTime)
  577.  
  578.             task.wait(openDoorTime)
  579.             carriageDoorDebounce = false
  580.             carriageOpenDoorButton.Light.Material = Enum.Material.Metal
  581.        
  582.             table.remove(floorQueue, 1)
  583.         else
  584.             local currentFloorDoors = floorDoors[currentFloor]
  585.             local currentLeftDoor = currentFloorDoors.LeftDoor
  586.             local currentRightDoor = currentFloorDoors.RightDoor
  587.            
  588.             local isOpen = cframeValueLeft.Value.Position.Magnitude > 0 or cframeValueRight.Value.Position.Magnitude > 0
  589.            
  590.             if not isOpen then
  591.                
  592.                 carriageDoorDebounce = true
  593.  
  594.                 carriageOpenDoorButton.Light.Material = Enum.Material.Neon
  595.  
  596.                 local leftGoalCF = CFrame.new(currentLeftDoor.PrimaryPart.Size.X * currentLeftDoor.PrimaryPart.CFrame.RightVector)
  597.                 local rightGoalCF = CFrame.new(currentRightDoor.PrimaryPart.Size.X * -currentRightDoor.PrimaryPart.CFrame.RightVector)
  598.  
  599.                 task.spawn(tween, currentLeftDoor.CFrameValue, leftGoalCF, openDoorTime)
  600.                 task.spawn(tween, currentRightDoor.CFrameValue, rightGoalCF, openDoorTime)
  601.  
  602.                 if doorOpenSound then
  603.                     doorOpenSound:Play()
  604.                 end
  605.  
  606.                 task.wait(0.2)
  607.  
  608.                 local leftCarriageDoorGoalCF = CFrame.new(carriageLeftDoor.PrimaryPart.Size.X * carriageLeftDoor.PrimaryPart.CFrame.RightVector)
  609.                 local rightCarriageDoorGoalCF = CFrame.new(carriageRightDoor.PrimaryPart.Size.X * -carriageRightDoor.PrimaryPart.CFrame.RightVector)
  610.  
  611.                 task.spawn(tween, cframeValueLeft, leftCarriageDoorGoalCF, openDoorTime)
  612.                 task.spawn(tween, cframeValueRight, rightCarriageDoorGoalCF, openDoorTime)
  613.  
  614.                 task.wait(openDoorTime)
  615.                 carriageOpenDoorButton.Light.Material = Enum.Material.Metal
  616.                 carriageDoorDebounce = false
  617.             end
  618.            
  619.             table.remove(floorQueue, 1)
  620.         end
  621.        
  622.         task.wait(4)
  623.     end
  624. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement