I am creating a tower defense game and basing wave strength off of what round that game is on.
Every 5 rounds a boss will spawn. Instead of creating a block of code for every (5, 10, 15, 20… etc.) round the player is on, I created a table of these values.
The idea behind this code is it checks the wave (round) and if the that value is within the table then a boss will spawn.
for wave=5, 20 do
print("WAVE HAS STARTED:", wave)
workspace.GameValues.Round.Value += 1
if wave < 5 then
for count=1,wave do
mob.Spawn("fein", 2, map)
mob.Spawn("fastboi", 1, map)
end
elseif wave == fifthWaves[wave] then
print("boss wave", wave)
mob.Spawn("fein", 10 * wave, map)
task.wait(2)
mob.Spawn("megafein", 1 * wave, map)
mob.Spawn("monster", 1 * wave, map)
elseif wave > 5 then
for count=1,wave do
mob.Spawn("fein", 1, map)
mob.Spawn("megafein", 1, map)
mob.Spawn("fastboi", 1, map)
mob.Spawn("monster", 1, map)
end
end
repeat
task.wait(5)
until #workspace.MobRealm:GetChildren() == 0 or gameOver
if gameOver then
print("GameOver pig")
break
end
print("WAVE HAS ENDED:", wave)
task.wait(1)
end
The wave is just set at the top and isn’t an actual value in the game
You’re checking to see if the wave number is equal to some entry in a table, instead you need to check if there is an entry in that table at the given position. Try the following instead:
elseif fifthWaves[wave] ~= nil then
Alternatively, if you always want a boss fight every 5 waves, you can just use a modulus operation; see the following: