Humanoid:MoveTo() paremeters?

Yeah okay, im a noob i can take that

because i am

But im kinda confused, i usesually use ‘Humanoid:MoveTo()’ using only one parameter and going through a script it had 2 parameters
I tried searching in the wiki and it just made me more confused… can someone explain me how this works?

:MoveTo() uses 2 total parameters but the last one is optional. It accepts a location Vector3 for its first parameter and a part Instance for its second parameter. So, you can do either:

:MoveTo(Vector3.new(5, 3, 5)) -- Go to this point

or

:MoveTo(Vector3.new(), workspace.RandomPerson.HumanoidRootPart) -- Follows character

You can find this info on the Type and Default values shown on the wiki.

1 Like

I honestly don’t why that parameter exists, because if you were to pass in the first parameter you would pass in the vector, hence the second parameter wouldn’t be needed. Besides, there is never gonna be a case where you use the second parameter, since and I might be wrong here, but if you pass in both parameters, then the first parameter would be still used, so it basically makes the second parameter useless.

1 Like

The second parameter is useful for following characters and no, the first parameter is not ignored. Instead, the first parameter becomes relative to the instance (2nd parameter). So, using :MoveTo(Vector3.new(0, 0, -4), partToFollow) would make the NPC follow 4 studs ahead of the character. The second parameter will also update the goal if the part moves as told in the wiki:

However, if the part moves then the point the Humanoid is walking to will move to be at the same position relative to the part

Meanwhile, just setting the 1st parameter without the 2nd will use world coordinates instead of relative to the instance.

2 Likes