A problem with a module script

Alright so i’m making a tower defense game and i got this script

local ServerStorage = game:GetService("ServerStorage")
local MOB = {}
function MOB.Move(mob, map)
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = workspace.WayPoints

	for waypoint=1, #waypoints:GetChildren() do
		mob.Humanoid:MoveTo(waypoints[waypoint].Position)
		mob.Humanoid.MoveToFinished:Wait()
	end
	
	mob:Destroy()
end
function MOB.Spawn(name, quantity, map)
	local mobExists = ServerStorage.MOBS:FindFirstChild(name)

	if mobExists then
		for i=1, quantity do
			task.wait(0.5)
			local newMob = mobExists:Clone()
			newMob.HumanoidRootPart.CFrame = workspace.MAP.ZombieSpawn.CFrame
			newMob.Parent = workspace
		end
		
		coroutine.wrap(MOB.Move)(newMob, map)
	else
		warn("idk")
	end
end

return MOB

the problem is that it gives me this error

ServerScriptService.Main.MainModuleScript:25: invalid argument #1 to ‘wrap’ (function expected, got table)

what do i do??

1 Like

Replace: for i=1, quantity do with for i = 1, #quantity do.
You are passing the table itself, not the length. The “#” operator gets the length of a table.

2 Likes

Alright so uhhh ive tried that and it still doesn’t work.

1 Like

Hmm. Try moving the coroutine function inside of the for loop.

2 Likes

You are calling the function incorrectly

for example you could do this

coroutine.wrap()
moduke.MOB.Move(newMob, map)
end()

This is the wrong format btw I’m on phone

1 Like

That is incorrect, he’s calling the function correctly.

1 Like

I’ve gotta be doing something wrong because that same script worked correctly before.

Unfortunately this is not true, coroutine.wrap should look like this:

coroutine.wrap(func) (arg)

As for solving this problem try doing:

print(type(MOB.Move))

If it returns a table, then that means that it is converted somewhere in your script.

1 Like

Thats why I noted I had it written wrong, sometimes (couldn’t say why) writing it another way makes it work

especially in this instance where he said it worked before

2 Likes

Alright so uhhh it kind of works but the characters are kind of uhhhh

Btw sorry for the lag, im on a laptop

1 Like

Your script is correct, what are you trying to do. Are you trying to make them spawn side-by-side or without collision for example?

Alright so im just trying to make them spawn per wave like this video shows:

1 Like

theres also a part 1 i forgot to include

I’m not entirely sure if this is true since I don’t know because it doesn’t show the code with how the waypoint table is set up, but here’s what I think is happening:

When the MOBS spawn, they are all fighting against each other to get to the first waypoint (you made the spawn a waypoint) this causes them to jump around since the MOBS are constantly trying to get to the waypoint.

If this is your issue you can remove the first waypoint by doing:

table.remove(waypoints, 1)
1 Like

Okay uhhhh… idk what to say, ill just leave the serverscript thats in serverscriptservice in here

local mob = require(script.MainModuleScript)
local map = workspace.MAP

for wave=1, 30 do
	warn("WARNING ZOMBIES INCOMING, also yeah i just did a warning instead of printing because i like to :D")
	mob.Spawn("Normal", 3, map)
	if wave == 2 then
		mob.Spawn("Speed", 3, map)
	end
end
1 Like