Attempt to index nil with 'Start'

I’ve been having this bug for a while on my game and I dont know how to fix it I’m please help me
here’s my code

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
			newMob.Parent = map.Mob

			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

It gives me the error attempt to index nil with ‘Start’

Hi! I think the primary issue here is that in the line “map.Start.CFrame” you are getting nil for map. My suggestion would be try to define a global variable (under local mob = {}) like this:

local map = nil

Then update your map value (I am unfamiliar with how you get your mapdata) somewhere in mob.spawn as map = (UPDATEVALUEHERE). This should fix the nil issue if you have a map. This is because right now you have map as a parameter, but it is nil or undefined. I hope this helps!

can you show us the part where you use the function mob.Spawn()?

1 Like

Main script in ServerScriptStorage

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

for wave=1, 5 do
	print("Wave STARTING:", wave)
	if wave < 5 then
		mob.Spawn("Zombie", 3 * wave, map)
		mob.Spawn("Fast", 3)
	elseif wave ==5 then
		mob.Spawn("Zombie", 100,  map)
	end

	repeat
		task.wait(1)
	until #map.Mob:GetChildren() == 0

	print("WAVE ENDED")
	task.wait(1)
end

check your map in the explorer if “Start” even exists. you should also use :FindFirstChild() or :WaitForChild()

Turns out I forgot to label the starting point ‘Start’ thank you for helping me

1 Like

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