Help simplify a script

can anyone help me make those statements into one singular if statement ?

FloorNumber = ElevatorHandler.CurrentFloor.Value

	if FloorNumber == 0 then
		workspace.CurrentFloor:FindFirstChildWhichIsA("Folder"):Destroy()
		local ChosenFloor = CurrentLayer.LayerDefault
		local FloorClone = ChosenFloor:Clone()
		FloorClone.Parent = workspace.CurrentFloor
		CurrentFloorType = "Safe"
		task.wait(0.5)
		AnomalyButton.ClickDetector.MaxActivationDistance = 10
		return
	elseif FloorNumber == 5 then
		workspace.CurrentFloor:FindFirstChildWhichIsA("Folder"):Destroy()
		local ChosenFloor = CurrentLayer.LayerDefault
		local FloorClone = ChosenFloor:Clone()
		FloorClone.Parent = workspace.CurrentFloor
		CurrentFloorType = "Safe"
		task.wait(0.5)
		AnomalyButton.ClickDetector.MaxActivationDistance = 10
		return
	elseif FloorNumber == 10 then
		workspace.CurrentFloor:FindFirstChildWhichIsA("Folder"):Destroy()
		local ChosenFloor = CurrentLayer.LayerDefault
		local FloorClone = ChosenFloor:Clone()
		FloorClone.Parent = workspace.CurrentFloor
		CurrentFloorType = "Safe"
		task.wait(0.5)
		AnomalyButton.ClickDetector.MaxActivationDistance = 10
		return
			
	else

i tried doing if FloorNumber == 0 or 5 or 10 then but that doesnt seem to work, even if the FloorNumber is not equal to 0 or 5 or 10 (ex. FloorNumber is 2 or 7 or 9), it still goes thu the statement . if u need more information, please specify what and i will provide, thx

Be sure to check that your if statement includes the variable being compared to 5 or 10.

You said:

if FloorNumber == 0 or 5 or 10 then

But in order to actually compare it to 5 it’d have to read:

if FloorNumber == 0 or FloorNumber == 5 or FloorNumber == 10 then
1 Like

You could use the modulo operator, which returns the remainder of a division operation. In your case, if (FloorNumber % 5) == 0 then
If you wanted to account for the FloorNumber = 0 too, then just add 5 onto the value when using the operator:
if ((FloorNumber+5) % 5) == 0 then

1 Like

You could do: % modulo operator

if (FloorNumber % 5) == 0 then
1 Like

You could try storing all of the FloorNumber in a table with a function representing them:

--Script

FloorNumber = ElevatorHandler.CurrentFloor.Value::number

local HandleSafeFloors = function()
	workspace.CurrentFloor:FindFirstChildWhichIsA("Folder"):Destroy()
	local ChosenFloor = CurrentLayer.LayerDefault
	local FloorClone = ChosenFloor:Clone()
	FloorClone.Parent = workspace.CurrentFloor
	CurrentFloorType = "Safe"
	task.wait(0.5)
	AnomalyButton.ClickDetector.MaxActivationDistance = 10
	return
end

local SafeFloors = {
  [0] = HandleSafeFloors,
  [5] = HandleSafeFloors,
  [10] = HandleSafeFloors
}

local currentfloor = SafeFloors[FloorNumber]
if currentfloor then
     currentfloor()
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.