I’m trying to make an elevator, and each segment of the following code corresponds to one of the four buttons this elevator has. The problem I have is that only the first two segments actually do something. I’m pretty sure it has to do something with the order in which I wrote the code, but I appreciate any help.
local TweenService = game:GetService("TweenService")
local elev = script.Parent.elevator.Platform
local tweenInfo = TweenInfo.new(3.0, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local tween = TweenService:Create(elev, tweenInfo, {Position = elev.Position + Vector3.new(0, 43.8, 0)})
script.Parent.downbutton.UP.ClickDetector.MouseClick:Connect(function(plr)
script.Parent.elevator.Click:Play()
script.Parent.elevator.moving:Play()
tween:Play()
wait(3)
script.Parent.elevator.moving:Stop()
script.Parent.elevator.Blocker1.CanCollide = true
script.Parent.elevator.Blocker3.CanCollide = false
script.Parent.elevator.Blocker4.CanCollide = true
script.Parent.elevator.Blocker2.CanCollide = false
local tween2Info = TweenInfo.new(3.0, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tween2 = TweenService:Create(elev, tween2Info, {Position = elev.Position + Vector3.new(0, -43.8, 0)})
script.Parent.downcall.downcall.ClickDetector.MouseClick:Connect(function(plr)
script.Parent.elevator.Click:Play()
script.Parent.elevator.moving:Play()
tween2:Play()
wait(3)
script.Parent.elevator.moving:Stop()
script.Parent.elevator.Blocker1.CanCollide = false
script.Parent.elevator.Blocker3.CanCollide = true
script.Parent.elevator.Blocker4.CanCollide = false
script.Parent.elevator.Blocker2.CanCollide = true
local tween3Info = TweenInfo.new(3.0, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tween3 = TweenService:Create(elev, tween3Info, {Position = elev.Position + Vector3.new(0, -43.8, 0)})
script.Parent.upbutton.DOWN.ClickDetector.MouseClick:Connect(function(plr)
script.Parent.elevator.Click:Play()
script.Parent.elevator.moving:Play()
tween3:Play()
wait(3)
script.Parent.elevator.moving:Stop()
script.Parent.elevator.Blocker1.CanCollide = true
script.Parent.elevator.Blocker3.CanCollide = false
script.Parent.elevator.Blocker4.CanCollide = true
script.Parent.elevator.Blocker2.CanCollide = false
local tween4Info = TweenInfo.new(3.0, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tween4 = TweenService:Create(elev, tween4Info, {Position = elev.Position + Vector3.new(0, 43.8, 0)})
script.Parent.upcallbutton.upcall.ClickDetector.MouseClick:Connect(function(plr)
script.Parent.elevator.Click:Play()
script.Parent.elevator.moving:Play()
tween4:Play()
wait(3)
script.Parent.elevator.moving:Stop()
script.Parent.elevator.Blocker1.CanCollide = false
script.Parent.elevator.Blocker3.CanCollide = true
script.Parent.elevator.Blocker4.CanCollide = false
script.Parent.elevator.Blocker2.CanCollide = true
end)
end)
end)
end)