I need some help using elseif statements...

Hey guys, so I’m a little new to the forums, as well as lua, although i’ve done a little bit of java and lua before. Anyway, I found a game mode base that im working on to play with friends, but I hit a little bit of a rut with the elseif statements, can someone help me out?

		--  Check 'em against max amounts.
		local zombiespawn = (#zombies < maxzombies)
		local fastzomspawn = (#fastzoms < maxfastzoms)
		local poisonzomspawn = (#poisonzoms < maxpoisonzoms)
		local antlionspawn = (#antlions < maxantlions)
		local antguardspawn = (#antguards < maxantguards)
		if zombiespawn or fastzomspawn or poisonzomspawn or antlionspawn or antguardspawn then
			--  Add 'em to a table with how much they need.
			if zombiespawn then rng1 = math.random(150)
				if rng1 >= 5 then spawnables["npc_vj_mwjuggernaut"] = maxzombies - #zombies end
				elseif rng1 >= 6 and rng1 =< 10 then spawnables["npc_loner_exo_unit"] = maxzombies - #zombies end
				elseif rng1 >= 11 and rng1 =< 20 then spawnables["npc_uar_veteran"] = maxzombies - #zombies end
				elseif rng1 >= 21 and rng1 =< 35 then spawnables["npc_monolith_s"] = maxzombies - #zombies end
				elseif rng1 >= 36 and rng1 =< 50 then spawnables["npc_winter_s"] = maxzombies - #zombies end
				elseif rng1 >= 51 and rng1 =< 65 then spawnables["npc_mil_stalker"] = maxzombies - #zombies end
				elseif rng1 >= 66 and rng1 =< 80 then spawnables["npc_st_bandit_master"] = maxzombies - #zombies end
				elseif rng1 >= 81 and rng1 =< 110 then spawnables["npc_st_bandit"] = maxzombies - #zombies end
				elseif rng1 >= 111 then spawnables["npc_fastzombie"] = maxzombies - #zombies end
			if fastzomspawn then spawnables["npc_fastzombie"] = maxfastzoms - #fastzoms end 
			if poisonzomspawn then spawnables["npc_poisonzombie"] = maxpoisonzoms - #poisonzoms end
			if antlionspawn then spawnables["npc_antlion"] = maxantlions - #antlions end
			if antguardspawn then 
				if math.random(1,10) == 1 then
					spawnables["npc_antlionguard"] = 1

Right, so the spawn table fine when it can only spawn one npc all the time (etc. if I had instead of that big list just spawnables[“npc_loner_exo_unit”] would work and spawn that unit each time no problem) but what im trying to do is make the call spawn a random npc from a list of predetermined npcs, they’re all set up and work, and there arent any errors showing up in console, my biggest problem is the elseifs are connecting to the wrong ifs and causing end statements to go willy nilly everywhere. the fastzom/poisonzom/etc spawns are disabled as well, so every time it checks it should only do zombiespawn. Is there any command or something I can put in that will do what im trying to do here a little bit better?

edit: completely off topic, but I forgot an extra K in my name and I cant seem to be able to change my username, idk if I can fix that or just have to deal with the ocd all my time here, but if someone could help me fix that that would be great!

You’re ending the statements. You only need to do that on the last one.

Wow, I cant believe I missed that. I’ve been working on this one segment for about 16 hours today and rewrote half of the whole thing two or three times, thats honestly a little disappointing.

However, after doing this fix its saying that I need a then statement near my = for the second line (one spawning loner_exos) and i’m assuming since this is the first of the list all of them as well. Is my then in a bad place? Again, sorry for all these questions but been a long day and to be honest im not really that sure of what im doing…

This should work and give you more of an idea how to use elseif statements.

if (zombiespawn) then
	local rng1 = math.random(9)

	if (rng1 == 1) then
		spawnables["npc_vj_mwjuggernaut"] = maxzombies - #zombies
	elseif (rng1 == 2) then
		spawnables["npc_loner_exo_unit"] = maxzombies - #zombies
	elseif (rng1 == 3) then
		spawnables["npc_uar_veteran"] = maxzombies - #zombies
	elseif (rng1 == 4) then
		spawnables["npc_monolith_s"] = maxzombies - #zombies
	elseif (rng1 == 5) then
		spawnables["npc_winter_s"] = maxzombies - #zombies
	elseif (rng1 == 6) then
		spawnables["npc_mil_stalker"] = maxzombies - #zombies
	elseif (rng1 == 7) then
		spawnables["npc_st_bandit_master"] = maxzombies - #zombies
	elseif (rng1 == 8) then
		spawnables["npc_st_bandit"] = maxzombies - #zombies
	elseif (rng1 == 9) then
		spawnables["npc_fastzombie"] = maxzombies - #zombies

Great thanks! This works really well except for two little things that I can start to work on tomorrow unless you’re interested and want to see if you can solve it lol. The first thing is that all the zombiespawn calls trigger at once, meaning that if the rng chooses 4 ALL of the things being spawned will be monolith, and so on. This is a little bit of a problem because the goal is to have multiple spawn points that should randomly spawn things across the entire map, and the other issue that isnt that big is that all the npcs are different difficulty, which was also why the rng was put with such different numbers, the easiest were supposed to spawn more frequently to keep it from someone killing all the easy guys and it being filled with hard guys that only elite players could beat.

Again, thanks for the code! it works brilliantly and I can start to work on some other stuff once I get those things down.