so i’ve been trying to organize a way to spawn enemies through tables on a modulescript, and, to make my life easier, i also created this function that can repeat through a bunch of enemies at once, throw them into a table, and then i can just unpack them to add 40 in 1 line of code. however, when i have multiple of these functions in 1 wave, the ones after replace the ones before them.
how can i make both functions run without overlapping and covering their predecessors
MODULESCRIPT:
function Repeat(Enemy,amount,Table)
local repeats = 0
repeat
table.insert(Table,Enemy)
repeats += 1
until
repeats == amount
return Table
end
local Waves = {
["Wave 1"] = {
table.unpack(Repeat(game.ServerStorage.Noob,40,{})),
},
["Wave 2"] = {
table.unpack(Repeat(game.ServerStorage.Noob,20,{})),
table.unpack(Repeat(game.ServerStorage.Sworder,20,{})),
},
["Wave 3"] = {
table.unpack(Repeat(game.ServerStorage.Noob,50,{})),
table.unpack(Repeat(game.ServerStorage.Sworder,30,{})),
},
["Wave 4"] = {
table.unpack(Repeat(game.ServerStorage.Booster,10,{})),
table.unpack(Repeat(game.ServerStorage.Noob,30,{})),
table.unpack(Repeat(game.ServerStorage.Sworder,15,{})),
},
["Wave 5"] = {
table.unpack(Repeat(game.ServerStorage.Tanker,5,{})),
table.unpack(Repeat(game.ServerStorage.Noob,30,{})),
},
}
return Waves
printed message of wave 2:
(1 noob then 20 sworders)