What do you want to achieve?
An elevator that can move between 2 floors
What is the issue?
The issue is that the door on the 2nd floor isnt closing after moving from 2nd floor to 1st floor
What solutions have you tried so far?
I have tried setting the door open at the start, and then closing it
Here is the code:
local floor1button = script.Parent.Elevator.Down.ClickDetector
local floor2button = script.Parent.Elevator.Up.ClickDetector
local door1 = script.Parent.Elevator.Door1
local door2 = script.Parent.Door2
local door3 = script.Parent.Door3
local debounce = false
local tweenService = game:GetService("TweenService")
local floor = 1
local function closeDoors()
local tweenInfo = TweenInfo.new(5,Enum.EasingStyle.Linear)
local goals2 = {}
goals2.Position = door2.Position + Vector3.new(5,0,0)
local tween = tweenService:Create(door2,tweenInfo,goals2)
tween:Play()
------------
local tweenInfo = TweenInfo.new(5,Enum.EasingStyle.Linear)
local goals1 = {}
goals1.Position = door1.Position + Vector3.new(5,0,0)
local tween = tweenService:Create(door1,tweenInfo,goals1)
tween:Play()
------------
local tweenInfo = TweenInfo.new(5,Enum.EasingStyle.Linear)
local goals3 = {}
goals1.Position = Vector3.new(-11.2, 84.35, -70.05)
local tween = tweenService:Create(door3,tweenInfo,goals3)
tween:Play()
end
local function openDoors()
local tweenInfo = TweenInfo.new(5,Enum.EasingStyle.Linear)
local goals2 = {}
goals2.Position = door2.Position - Vector3.new(5,0,0)
local tween = tweenService:Create(door2,tweenInfo,goals2)
tween:Play()
------------>
local tweenInfo = TweenInfo.new(5,Enum.EasingStyle.Linear)
local goals1 = {}
goals1.Position = door1.Position - Vector3.new(5,0,0)
local tween = tweenService:Create(door1,tweenInfo,goals1)
tween:Play()
------------>
local tweenInfo = TweenInfo.new(5,Enum.EasingStyle.Linear)
local goals3 = {}
goals3.Position = Vector3.new(-15.9, 84.35, -70.05)
local tween = tweenService:Create(door3,tweenInfo,goals3)
tween:Play()
------------>
end
local function moveUp()
closeDoors()
wait(5)
for i,v in pairs (script.Parent.Elevator:GetChildren()) do
local tweenInfo = TweenInfo.new(20,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut)
local goals = {}
goals.Position = v.Position + Vector3.new(0,80,0)
local tween = tweenService:Create(v,tweenInfo,goals)
tween:Play()
tween.Completed:Connect(function()
openDoors()
wait(5)
debounce = false
floor = 2
end)
end
end
local function moveDown()
closeDoors()
wait(5)
for i,v in pairs (script.Parent.Elevator:GetChildren()) do
local tweenInfo = TweenInfo.new(20,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut)
local goals = {}
goals.Position = v.Position - Vector3.new(0,80,0)
local tween = tweenService:Create(v,tweenInfo,goals)
tween:Play()
tween.Completed:Connect(function()
openDoors()
wait(5)
debounce = false
floor = 1
end)
end
end
floor1button.MouseClick:Connect(function()
if debounce == false and floor == 2 then
debounce = true
moveDown()
end
end)
floor2button.MouseClick:Connect(function()
if debounce == false and floor == 1 then
debounce = true
moveUp()
end
end)
And here is the directory of the parts and buttons
"Up" is the button to take the elevator to the second floor
"Down" is the button to take the elevator to the first floor
"Elevator" is the model containing the actual elevator