Help on tower defense like wave system

Hey! So, u probably already played a tower defense game and you know that it is based on waves with a set amount of zombies, but im not finding a way to make that system

Can anyone help me do it?

The script that is supposed to spawn things

local smodule = require(game.ReplicatedStorage.Modules.Scripting.Spawner)
local edata = require(game.ReplicatedStorage.Modules.Data.EnemyData)
local wdata = require(game.ReplicatedStorage.Modules.Data.WaveData)

local waves = wdata:GetChildren()

function spawnmob(tospawn)
	smodule.spawnmob(tospawn)
end

for i = 1, #waves do
	spawnmob(table.concat(wdata)) -- i think this like is the error
	task.wait(2)
end

Module script if anyone needs

local waves = {
	["1"] = {
		"Normal",
		"Normal",
		"Normal",
		"Normal"
	},
	["2"] = {
		"Normal",
		"Normal",
		"Normal",
		"Normal",
		"Normal",
		"Normal",
		"Normal"
	},
	["3"] = {
		"Speedie",
		"Speedie",
		"Speedie",
		"Speedie",
		"Speedie",
	}
}
return waves

about the error line i dont know how to use table.concat for it, im not really experienced with it

2 Likes

I would probably instead iterate over subtables which specify how many of a certain type of enemy to spawn, you could also add in additional configs such as the time between enemy spawns, time to wait after all enemies in that group have spawned, etc.

Certainly easier than writing hundreds of individual enemies, you could try something like:

local waves = {
[1] = {
{
enemyType = "Speedie";
enemyAmount = 5;
timeBetweenSpawn = .5;
}
};
}

And to process the wave data you could do:

local function spawnEnemies(waveData) --//waveData being an index out of the 'waves' table
for _, enemyGroup in ipairs(waveData) do
for i = 1, enemyGroup.numberOfEnemies do
spawnmob(enemyGroup.enemyType)

task.wait(enemyGroup.timeBetweenSpawns)
end
end
end
1 Like

I changed to that after i published that post, and also i found a dev log on youtube and fixed the script, thanks anyways!