I know I’m doing this wrong

Hey, so I’m trying to make an exit button, but I’m not very good with “elseif” and I don’t know how to use it. Mind helping me? Also, please don’t judge, I’m trying my best. :frowning:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local movingEvent = ReplicatedStorage:WaitForChild("MovingElevator")
local elevatorEvent = ReplicatedStorage:WaitForChild("Elevator")
local elevatorEvent2 = ReplicatedStorage:WaitForChild("Elevator2")
local elevatorEvent3 = ReplicatedStorage:WaitForChild("Elevator3")
local elevatorEvent4 = ReplicatedStorage:WaitForChild("Elevator4")
local elevatorEvent5 = ReplicatedStorage:WaitForChild("Elevator5")
local gui = script.Parent
local exitBtn = gui.Exit
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local Values = player:FindFirstChild("Values")

movingEvent.OnClientEvent:Connect(function()
	exitBtn.Visible = false
end)

elevatorEvent.OnClientEvent:Connect(function(elevator)
	exitBtn.Visible = true
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = elevator.Camera.CFrame
end)

local eventFolder = game.ReplicatedStorage.EventFolder -- This is the folder holding the events
exitBtn.Activated.Connect(function()
	exitBtn.Visible = false
	camera.CameraType = Enum.CameraType.Custom
	camera.CameraSubject = player.Character.Humanoid

	-- Fire the corresponding elevator number's event
	eventFolder["elevatorEvent"..Values.ElevatorNumber.Value]:FireServer()

	-- If the above line does not work, try the line below instead:
	--eventFolder:FindFirstChild("elevatorEvent"..Values.ElevatorNumber.Value):FireServer()

	-- Use tasks for efficiency
	task.defer(function()
		task.wait(0.1)
		Values.ElevatorNumber.Value = 0
	end)
end)

you wouldn’t need an elseif here, you don’t have an if

1 Like

Why not store the elevators like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local elevators = {ReplicatedStorage:WaitForChild("Elevator"), ReplicatedStorage:WaitForChild("Elevator2"), ReplicatedStorage:WaitForChild("Elevator3"), ReplicatedStorage:WaitForChild("Elevator4"), ReplicatedStorage:WaitForChild("Elevator5")}

Then they can be accessed like elevators[3] (For Elevator3)

1 Like