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

Why does my NPC stop moving mid-walk to a point?

Asked by 6 years ago

So I have this script

script.Parent.Parent.Giant.Humanoid:MoveTo(game.Workspace.WalkTwo.Position)

The script above stops moving doe...

Here is what it looks like : https://i.gyazo.com/d15d5c46690fa0ce4d258669c2c55c05.mp4

0
because the NPC gets tired so it stops for a break awesomeipod 607 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

There is a time limit to MoveTo. If it does not reach its destination point it will fire MoveToFinished with false.

You could use this and run the MoveTo function again.

local humanoid = script.Parent.Parent.Giant.Humanoid
local vecList = {
    -- list of positions vector3
}
local curPoint = 1 -- holds the current walk to point

humanoid:MoveTo(vecList [curPoint]) -- the first point 

humanoid.MoveToFinished:Connect(function(foundEnd)
    if foundEnd then
        curPoint = curPoint  + 1 -- go to next point if found
    end
    if vecList [curPoint] then -- check we have a vector3 to walk to
        humanoid:MoveTo(vecList [curPoint])
    else
        print('end') -- no more points
    end
end)

I hope this helps.

0
Yes this helps but the script isn't working? I've changed my vecList to local vecList = { game.Workspace.WalkOne } but it doesn't walk to it, and also I got an error, 'Giant is not a valid member of DataModel' ? how do I fix this. So yeah I want to make this cause I'm making a sort of Tower Battles game xD TheOnlySmarts 233 — 6y
0
game.Workspace.WalkOne is an instance not the vector 3. Use the Position which is a vector3 User#5423 17 — 6y
0
Okay thank you so much!! IT WORKS :D TheOnlySmarts 233 — 6y
Ad

Answer this question