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?
In line 15, inside the parenthesis, why is there a "mob" inside when there's already a table named "mob", try changing it to function mob.Move(mobCharacter, map)
maybe that's what causing the error.
for waypoint=3, #waypoints:GetChildren()-2 do
OR
for waypoint=1, #waypoints:GetChildren() do
Fixed code
function mob.Move(mob, map) local humanoid = mob:WaitForChild("Humanoid") local waypoints = workspace.Grassy.waypoints local waypoint = 3 while waypoint <= #waypoints:GetChildren() do humanoid:MoveTo(waypoints[waypoint].Position) humanoid.MoveToFinished:Wait() waypoint += 1 end mob:Destroy() end
I don't think I have to explain this one.