'Humanoid:MoveTo() doesn't work | Roblox LUA
So i'm trying to make a little bot that moves to a point in the map Here is my code :
local character = script.Parent
local humanoid = character.Humanoid
local testpoint = character.Parent.Points["End Part 2"].Position
humanoid:MoveTo(testpoint)
humanoid.MoveToFinished:Connect(function()
print("Reached Dest")
end)
when i launch the game, the dummy model doesn't move at all (even if WalkToPoint have been correctly set)
and then after a few seconds the message Reached Dest
prints in the console but the humanoid hasn't move.
I have no idea why this happend, could you please help me.
Thank you so much.
Solution 1:[1]
I have seen problems before with trying to store an instances attribute in a variables. You should try:
local character = script.Parent
local humanoid = character.Humanoid
local testpoint = character.Parent.Points["End Part 2"]
humanoid:MoveTo(testpoint.Position)
humanoid.MoveToFinished:Connect(function()
print("Reached Dest")
end)
Also please make sure you are getting the previous variables correctly like character
and humanoid
Solution 2:[2]
humanoid:MoveTo(testpoint)
Aside from what I said below, testpoint is not set as a Vector, which ends up messing stuff up. A possible solution could be:
humanoid:MoveTo(Vector3.new(testpoint))
HOWEVER, You don't need to use MoveTo, I think you can use .Position just as easily, if you do this:
local character = script.Parent
local Torso = -- Get Torso somehow depending on your game rig
local pointToMove = character.Parent.Points["End Part 2"].Position
Torso.Position = Vector3.new(pointToMove)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Crann Moroney |
Solution 2 | 1BL1ZZARD |