In my tower defense game, there are waypoints in a folder, which zombies have to travel to.
Once they reach the last waypoint in the folder, they are normally supposed to be destroyed. However, it gives me the error "42 is not a valid member of Folder "Workspace.Grassy.waypoints".
local PhysicsService = game:GetService("PhysicsService")
local ServerStorage = game:GetService("ServerStorage")
local mob = {}
function mob.Move(mob, map)
local humanoid = mob:WaitForChild("Humanoid")
local waypoints = game.Workspace.Grassy.waypoints
for waypoint=3, #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 = 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
newMob.Humanoid.Died:Connect(function()
task.wait(0.03)
newMob:Destroy()
end)
coroutine.wrap(mob.Move)(newMob, map)
end
else
warn("rip")
end
end
return mob
When the amount of waypoints are less than 30..It works again..However when I place back all the waypoints leading up to 41 it starts malfunctioning again. Any help?

1 comment
"42 is not a valid member of Folder "Workspace.Grassy.waypoints" This error means that the 42nd waypoint doesn't exist in the waypoints folder. Adding a while loop might work