Confused why a script is not working

the entire script (Gnomecode tds tutorial – script until part 3)

local PhysicsService = game:GetService("PhysicsService")
local ServerStorage = game:GetService("ServerStorage")
local mob = {}

function mob.Move(mob, map)
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.Waypoints

	for waypoint=1, #waypoints:GetChildren() do
		humanoid:MoveTo(waypoints[waypoint].Position)
		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 = map.Start.CFrame -- error code here
			newMob.Parent = workspace.Mobs
			newMob.HumanoidRootPart:SetNetworkOwner(nil)
			for i, object in ipairs(newMob:GetDescendants()) do
				if object:IsA("BasePart") then
					PhysicsService:SetPartCollisionGroup(object, "Mob")
				end
			end
			
			coroutine.wrap(mob.Move)(newMob, map)
		end
		
	else
		warn("Requested mob does not exist:", name)
	end
end
return mob


I will add I am not the best at scriping. I have changed the variable map to where the actual map is located, but the game will have multiple maps, so I cannot change the variable without ruining the map-system.

1 Like

map is nil, you have not defined a valid object as a 3rd parameter and it is considered nil.
Reasons for that happening could be that you are sending from localscript to global and then to module while doing that, some local objects do not actually exist in the server and the variable is changed to nil.

If you could show the way it is called I be able to assist you to fixing the problem.

1 Like

If you could show the way it is called I be able to assist you to fixing the problem.

1 Like

here is the link if you want to check the script, I have looked through the entire video and for some reason cannot find the error, and find my script the same as in the video. [New Mob Types + Animations - Tower Defense Tutorial #3 - YouTube] [New Mob Types + Animations - Tower Defense Tutorial #3 -
link:New Mob Types + Animations - Tower Defense Tutorial #3 - YouTube

1 Like

You need to add a part named “Start” in the map.
It’s basically the spawn.

I’m pretty sure you did the code right but the map probably needs some stuff.

1 Like

Sure however I will need to see where you have called it. Can you try finding
where .Spawn() is used in your codes for spawning the mobs?

1 Like

I already have the Start part. I placed it inside of the map folder.

1 Like

Could you show me a picture of the map in explorer?
Could be parented wrong or it’s unanchored and fell out of the map.

1 Like

It is located in a different script.

local mob = require(script.Mob)
local map = workspace.Grassland

for wave = 1,30  do
	print("WAVE STARTING:", wave)
	if wave <= 2 then 
		mob.Spawn("Zombie", 5 * wave, map)
	elseif wave <= 5  then
		mob.Spawn("Zombie", wave, map)
		mob.Spawn("MiniBoss", wave, map)
	elseif wave <= 8  then
		mob.Spawn("Zombie", wave, map)
		mob.Spawn("boss", 1)
	elseif wave <= 29  then
		mob.Spawn("Zombie", wave, map)
		mob.Spawn("boss", 8, wave, map)

		

	end

	repeat
		task.wait(1)
	until #workspace.Mobs:GetChildren() == 0
	print("WAVE ENDED")
	task.wait(1)
end
1 Like

could you write on that script after:
local map = workspace.Grassland
Write on the next line:
print(map.Name)
and check if an error occurs in console
Provide it if it does. If not it would just print out the name ‘Grassland’

1 Like

Screenshot 2022-12-27 225410

1 Like

Oh okay, it’s a module which the function gets called.
Also check if everything is named correctly with capitalizations and stuff.

1 Like

Quick question, is “Start” anchored?

If it is, try using this script in place of the original.


local PhysicsService = game:GetService("PhysicsService")
local ServerStorage = game:GetService("ServerStorage")
local mob = {}

function mob.Move(mob, map)
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.Waypoints

	for waypoint=1, #waypoints:GetChildren() do
		humanoid:MoveTo(waypoints[waypoint].Position)
		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 = map:WaitForChild(“Start”).CFrame -- error code here
			newMob.Parent = workspace.Mobs
			newMob.HumanoidRootPart:SetNetworkOwner(nil)
			for i, object in ipairs(newMob:GetDescendants()) do
				if object:IsA("BasePart") then
					PhysicsService:SetPartCollisionGroup(object, "Mob")
				end
			end
			
			coroutine.wrap(mob.Move)(newMob, map)
		end
		
	else
		warn("Requested mob does not exist:", name)
	end
end
return mob

1 Like

In that case change the function to this:

2 Likes

Start is anchored.
textbecauseof30characterlimit

1 Like

The map is already defined in Argument 3 of the function though…

I mean it’s worth a try though.

1 Like

Try going into the game (press play) then see if “Start” is still in Grasslands.

If it isn’t that’s the issue, if it is, it’s probaby pathed wrong.

1 Like

start is still in grasslands. I do not believe it is pathed wrong, but it might be.

1 Like

If it is indeed still in Grasslands, you can try Foxy’s idea. Just straight out checking inside the map. Won’t work in the future if you have multiple maps though.

1 Like

I am sure that he doesn’t really need a map argument if he is using just one location.

1 Like