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)
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.
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:
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