If statement Overlapping eatch other

Hello so can you tell me why the if statement is overlapping eatch other and how to fix it?

playerEnter.Event:Connect(function(number)
	if number % 5 == 0   then
		workspace.Sounds.Flicker:Play()
		room.Blackout(generatedRooms[number])
		room.Blackout(generatedRooms[number+1])
		task.wait(2)
		skull.new(number, generatedRooms)
		return
	elseif number % 10 == 0 then
		workspace.Sounds.Flicker:Play()
		room.Blackout(generatedRooms[number])
		room.Blackout(generatedRooms[number+1])
		task.wait(2)
		GreenSkull.new(number, generatedRooms)
	end
end)

I’m not sure I understand your question correctly. Can you elaborate further?

So I am spawning the skull every 5 doors

And I wanna spawn the Greenskull every 10 doors
but they overlap eatch other so the greenskull can’t spawn because every 5 doors the skull spawns!

Simply flip the if and the elseif

if number % 10 == 0 then
	-- green skull
elseif number % 5 == 0 then
	-- skull
end

Change the order of the if statements:

if number % 10 == 0 then
elseif number % 5 == 0 then

When “number” is 100: 1st if statement passes
When “number” is 95: 1st if statement fails, 2nd if statement passes

1 Like

Still doesn`t work,any other ideas?

What Oblivic suggested is correct, you may be mis-interpreting what he meant.

I don’t have access to studio right now, but using the lua site, I can show proof that this indeed works as intended:

If statments run in the order in which they are defined, regardless of whether they evaluate to true or false. Your current implementation which you do not want is within func_y in my example, whereas what you want is contained within func_x. Note how the output shows that mod 10 is performed in the output of func_x rather than the mod 5.

1 Like

They are over lapping, and the fix is to flip the blocks around

	if number % 10 == 0 then
		workspace.Sounds.Flicker:Play()
		room.Blackout(generatedRooms[number])
		room.Blackout(generatedRooms[number+1])
		task.wait(2)
		GreenSkull.new(number, generatedRooms)
elsif number % 5 == 0   then
		workspace.Sounds.Flicker:Play()
		room.Blackout(generatedRooms[number])
		room.Blackout(generatedRooms[number+1])
		task.wait(2)
		skull.new(number, generatedRooms)
		return
	elseif number % 10 == 0 then
		workspace.Sounds.Flicker:Play()
		room.Blackout(generatedRooms[number])
		room.Blackout(generatedRooms[number+1])
		task.wait(2)
		GreenSkull.new(number, generatedRooms)
	end
end