How would I be able to insert two values within a table?

Heya There!

I’m working on a wave system for my game and I’m wondering how would I be able to add another value into the table? Not only I want to add a value of the enemy’s name but also the amount of enemies spawned in.

I tried looking through multiple DevForum post but they don’t seem to directly state how to implement one.

--[[MODULE REQUIRING]]--
local RoundHandler = require(script:WaitForChild("RoundHandler"))

--[[GAME]]--
--//Wave list & Current wave
local CurrentWave = 1
local WaveList = {
	[1] = {"Brickbattler"},
	[2] = {"Rioter"},
}

task.wait(8)
RoundHandler:StartNewWave(WaveList[CurrentWave])

task.wait(2)
CurrentWave = 2
RoundHandler:StartNewWave(WaveList[CurrentWave])

You can make use of dictionaries:

local WaveList = {
	[1] = {
		["Brickbattler"] = 5, --> 5 brick battlers
		["Zombie"] = 10, --> 10 zombies
	},
	[2] = {
		["Rioter"] = 5, --> 5 rioters
	},
}

If you were to spawn enemies in at round one, you would go through round one’s table and check the enemy type and how many:

for enemyName, numberEnemies in WaveList[1] do
 	print(`Spawned {numberEnemies} {enemyName}s`)
end
4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.