Script won't spawn enemies

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So, I’m making a wave-based attack system for my Tower defense game. I put all my wave information in a module script and require it afterwards.
  2. What is the issue? Include screenshots / videos if possible!
    Spawn script won’t spawn zombies according to the module script, instead it outputs an error saying the value is nil
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried to look up the solutions on different sites but found nothing so far. I also tried printing out the value and it works as intented but still won’t spawn.

Module Script:

local module = {}

module.Data = {
["Waves"] = {
	["WaveOne"] = {
	  "Zombie",
	  "Zombie",
	  "Zombie" },
	
	["WaveTwo"] = {
		"Zombie",
	    "Zombie",
	    "Zombie",
	    "Zombie",
		"Zombie" }
		}
}

return module

Spawn Script:

local WaveModule = require(script.WaveModule)
local Zombie = game.Workspace.Zombies.Zombie
local Speedy = game.Workspace.Zombies.Speedy
local ActiveZombies = game.Workspace.ActiveZombies


local function Spawn(Z)
	local Clone = Z:Clone()
	Clone.Parent = ActiveZombies
end


for i, v in pairs(WaveModule.Data.Waves.WaveOne)do
	Spawn(v)
end

The variable Clone is never used, what is it for?
Your Zombie and Speedy Zombie variables are never used either, this script doesn’t seem very complete.

I Want zombies to be spawned according to the module script, I think it should pass the variables and clone the zombie

You didn’t set the zombies’ new position:

local function Spawn(Z)
	local Clone = Z:Clone()
	Clone.Parent = ActiveZombies
	Clone:MoveTo(Vector3.new(math.random(-100, 100), 3, math.random(-100, 100)))
end

https://gyazo.com/145386b0d2074a739cff7b2d3a1bb873
I tried but it still outputed the same error.

You’re trying to clone a string to be used as an instance. Here’s a fix:

local function Spawn(Z)
	if Z then
		local Clone = Z:Clone()
		Clone.Parent = ActiveZombies
		Clone:MoveTo(Vector3.new(math.random(-100, 100), 3, math.random(-100, 100)))
	end
end


for i, v in pairs(WaveModule.Data.Waves.WaveOne)do
	Spawn(game.ReplicatedStorage.ZombieFolder[v])
end

You will need to make a folder named ZombieFolder to contain the enemies.

1 Like