In the following segment, everything works properly EXCEPT FOR the MoveTo() line.
As a section from a pathfinding AI, this code creates a tiny part at the location of the node for the zombie to move to. This part IS created, in the CORRECT place, but the zombie won't budge. The Humanoid's WalkSpeed is set to 8, and when I click on it in a running game, the property WalkToPart reads TargetPoint.
At best, I get a slight movement when the code first runs, but then they all freeze up.
No output errors. What's wrong?
x = 1 container = Instance.new("Model") container.Name = "TargetPointHolder" container.Parent = Workspace for i=1, #targetPath do targetpoint = Instance.new("Part") targetpoint.Name = "TargetPoint" targetpoint.Anchored = true targetpoint.CanCollide = false targetpoint.FormFactor = "Custom" targetpoint.Size = Vector3.new(0.2, 0.2, 0.2) targetpoint.Transparency = 1 targetpoint.Parent = container targetpoint.CFrame = CFrame.new(targetPath[x].Value) script.Parent.Zombie:MoveTo(targetPath[x].Value, targetpoint) --RIGHT HERE wait(8/script.Parent.Zombie.WalkSpeed + 0.1) x = x + 1 end
FYI - targetPath is a table containing Vector3 values that tell where each node along the path is located.
If targetPath is full of Vector3 values, you do not need to set .Value.
x = 1 container = Instance.new("Model") container.Name = "TargetPointHolder" container.Parent = Workspace for i=1, #targetPath do targetpoint = Instance.new("Part") targetpoint.Name = "TargetPoint" targetpoint.Anchored = true targetpoint.CanCollide = false targetpoint.FormFactor = "Custom" targetpoint.Size = Vector3.new(0.2, 0.2, 0.2) targetpoint.Transparency = 1 targetpoint.Parent = container targetpoint.CFrame = CFrame.new(targetPath[x]) script.Parent.Zombie:MoveTo(Vector3.new(targetPath[x]), targetpoint) --RIGHT HERE wait(8/script.Parent.Zombie.WalkSpeed + 0.1) x = x + 1 end
I have tested this in studio and it worked fine for me. You don't need.Value after a Vector3 from a table, MoveTo accepts a Vector3 then the part itself so you must use Vector3.new(targetPath[x])
you never indexed targetPath
so of course it won't work.
Turns out, this whole thing worked perfectly. It's just that when simulating a server in roblox studio, it bugged out. On the actual Roblox game servers, it all works just fine. :P