-- Sounds
local BeepSound1 = Door1.Door1.ElevatorBeep
local BeepSound2 = Door2.Door1.ElevatorBeep
local MoveSound1 = Door1.ElevatorMove1.ElevatorMove
local MoveSound2 = Door2.ElevatorMove1.ElevatorMove

Door1.Button1.ClickDetector.MouseClick:connect(function()
	if not debounce then
		debounce = true
		if not IsMoving and Floor == 2 then
			Door2.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame + (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame + (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			IsMoving = true
			wait(7)
			BeepSound1:Play()
			Door1.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 1
			IsMoving = false
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame - (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame - (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		elseif not IsMoving and Floor == 1 then
			Door1.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame + (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame + (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			IsMoving = true
			wait(7)
			BeepSound2:Play()
			Door2.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 2
			IsMoving = false
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame - (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame - (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		end
		debounce = false
	end
end)

Door1.ButtonScreen1.ClickDetector.MouseClick:connect(function()
	if not debounce then
		debounce = true
		if not IsMoving and Floor == 2 then
			Door2.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame + (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame + (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			IsMoving = true
			wait(7)
			BeepSound1:Play()
			Door1.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 1
			IsMoving = false
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame - (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame - (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		elseif not IsMoving and Floor == 1 then
			Door1.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame + (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame + (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			IsMoving = true
			wait(7)
			BeepSound2:Play()
			Door2.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 2
			IsMoving = false
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame - (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame - (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		end
		debounce = false
	end
end)

Door1.Button2.ClickDetector.MouseClick:connect(function(Player)
	if not debounce then
		debounce = true
		if not IsMoving then
			Door1.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame + (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame + (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			MoveSound1:Play()
			IsMoving = true
			wait(7)
			local TeleportTo = script.Parent.Elevator2:FindFirstChild("Floor")
			if TeleportTo ~= nil then
				local Torso = Player.Character.Torso
				local Location = (TeleportTo.Position)
				
				local X = Location.X
				local Y = Location.Y
				local Z = Location.Z
				local LX = 0
				local LY = Y
				local LZ = 0
				
				Y = Y + math.random(2, 3)
				Torso.CFrame = CFrame.new(Vector3.new(X,Y,Z), Vector3.new(LX,LY,LZ))
			end
			BeepSound2:Play()
			Door2.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 2
			IsMoving = false
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame - (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame - (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		end
		debounce = false
	end
end)

Door1.ButtonScreen2.ClickDetector.MouseClick:connect(function(Player)
	if not debounce then
		debounce = true
		if not IsMoving then
			Door1.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame + (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame + (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			MoveSound1:Play()
			IsMoving = true
			wait(7)
			local TeleportTo = script.Parent.Elevator2:FindFirstChild("Floor")
			if TeleportTo ~= nil then
				local Torso = Player.Character.Torso
				local Location = (TeleportTo.Position)
				
				local X = Location.X
				local Y = Location.Y
				local Z = Location.Z
				local LX = 0
				local LY = Y
				local LZ = 0
				
				Y = Y + math.random(2, 3)
				Torso.CFrame = CFrame.new(Vector3.new(X,Y,Z), Vector3.new(LX,LY,LZ))
			end
			BeepSound2:Play()
			Door2.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 2
			IsMoving = false
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame - (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame - (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		end
		debounce = false
	end
end)

Door2.Button1.ClickDetector.MouseClick:connect(function()
	if not debounce then
		debounce = true
		if not IsMoving and Floor == 1 then
			Door1.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame + (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame + (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			IsMoving = true
			wait(7)
			BeepSound2:Play()
			Door2.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 2
			IsMoving = false
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame - (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame - (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		elseif not IsMoving and Floor == 2 then
			Door2.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame + (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame + (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			IsMoving = true
			wait(7)
			BeepSound1:Play()
			Door1.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 1
			IsMoving = false
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame - (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame - (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		end
		debounce = false
	end
end)

Door2.ButtonScreen1.ClickDetector.MouseClick:connect(function()
	if not debounce then
		debounce = true
		if not IsMoving and Floor == 1 then
			Door1.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame + (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame + (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			IsMoving = true
			wait(7)
			BeepSound2:Play()
			Door2.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 2
			IsMoving = false
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame - (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame - (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		elseif not IsMoving and Floor == 2 then
			Door2.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame + (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame + (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			IsMoving = true
			wait(7)
			BeepSound1:Play()
			Door1.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 1
			IsMoving = false
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame - (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame - (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		end
		debounce = false
	end
end)

Door2.Button2.ClickDetector.MouseClick:connect(function(Player)
	if not debounce then
		debounce = true
		if not IsMoving and Floor == 2 then
			Door2.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame + (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame + (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			MoveSound2:Play()
			IsMoving = true
			wait(7)
			local TeleportTo = script.Parent.Elevator1:FindFirstChild("Floor")
			if TeleportTo ~= nil then
				local Torso = Player.Character.Torso
				local Location = (TeleportTo.Position)
				
				local X = Location.X
				local Y = Location.Y
				local Z = Location.Z
				local LX = 0
				local LY = Y
				local LZ = 0
				
				Y = Y + math.random(2, 3)
				Torso.CFrame = CFrame.new(Vector3.new(X,Y,Z), Vector3.new(LX,LY,LZ))
			end
			BeepSound1:Play()
			Door1.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 1
			IsMoving = false
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame - (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame - (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		end
		debounce = false
	end
end)

Door2.ButtonScreen2.ClickDetector.MouseClick:connect(function(Player)
	if not debounce then
		debounce = true
		if not IsMoving and Floor == 2 then
			Door2.Door1["Close" .. math.random(1,3)]:Play()
			for i = 1, 47 do
				Door2.Door1.CFrame = Door2.Door1.CFrame + (Door2.Door1.CFrame.lookVector * 0.10)
				Door2.Door2.CFrame = Door2.Door2.CFrame + (Door2.Door2.CFrame.lookVector * 0.10)
				wait()
			end
			MoveSound2:Play()
			IsMoving = true
			wait(7)
			local TeleportTo = script.Parent.Elevator1:FindFirstChild("Floor")
			if TeleportTo ~= nil then
				local Torso = Player.Character.Torso
				local Location = (TeleportTo.Position)
				
				local X = Location.X
				local Y = Location.Y
				local Z = Location.Z
				local LX = 0
				local LY = Y
				local LZ = 0
				
				Y = Y + math.random(2, 3)
				Torso.CFrame = CFrame.new(Vector3.new(X,Y,Z), Vector3.new(LX,LY,LZ))
			end
			BeepSound1:Play()
			Door1.Door1["Open" .. math.random(1,3)]:Play()
			Floor = 1
			IsMoving = false
			for i = 1, 47 do
				Door1.Door1.CFrame = Door1.Door1.CFrame - (Door1.Door1.CFrame.lookVector * 0.10)
				Door1.Door2.CFrame = Door1.Door2.CFrame - (Door1.Door2.CFrame.lookVector * 0.10)
				wait()
			end
		end
		debounce = false
	end
end)