Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

:MoveTo() not working?

Asked by 10 years ago

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.

0
Are you positive the "targetPath" locations are correct? User#2 0 — 10y

3 answers

Log in to vote
1
Answered by 10 years ago

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])

Ad
Log in to vote
0
Answered by
drahsid5 250 Moderation Voter
10 years ago

you never indexed targetPath so of course it won't work.

0
targetPath is, AS I EXPLAINED, "a table containing Vector3 values that tell where each node along the path is located." It was defined earlier in the script. ChiefWildin 295 — 10y
Log in to vote
0
Answered by 10 years ago

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

Answer this question