Help on identifying if something is an Instance or a number

I’m making a wave system for a Tower Defense game, and I have decided to create the waves in a form of a table.

module.Waves = {
	{enemies.Basic, 1, enemies.Basic, 1, enemies.Basic, 1, enemies.Basic}
}

function module.RunWaves()
	local wave = 1
	for i, v in pairs(module.Waves) do
		local currentWave = v
		local currentEnemy = currentWave[i] 
		-- This is where I am stuck, the number is meant to be the wait time between spawns, and the Instance is the enemy, I want to identify which is which.
		
	end
end

I don’t know how to detect if currentEnemy is a number or an instance, I would like to do this because in the system that I am creating, the Instance is the enemy being created, and the number is the wait time between spawns.

Any help is appreciated. Many Thanks.

1 Like

You can use type or typeof

module.Waves = {
	{enemies.Basic, 1, enemies.Basic, 1, enemies.Basic, 1, enemies.Basic}
}

function module.RunWaves()
	local wave = 1
	for i, currentWave  in pairs(module.Waves) do
		local currentWave = v
		local currentEnemy = currentWave[i] 
		
		if type(currentEnemy) == "number" then
			task.wait(currentEnemy)
		else
			-- spawn the enemy
		end

	end
end
2 Likes

Thank you, this worked perfectly in what I wanted to do.

1 Like

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