✓ Accepted answer
Use Pathfinding,
local TheFirst = script.Parent.TheNpc.Humanoid
local In = game.Workspace.FirstBrick
local Out = game.Workspace.SecondBrick
local Click = game.Workspace.Click
local path = game:GetService("PathfindingService"):ComputeRawPathAsync(In.Position, Out.Position, 500)
local points = path:GetPointCoordinates()
Click.ClickDetector.MouseClick:connect(function()
for _, point in pairs(points) do
print("moving to: ", point)
TheFirst:MoveTo(point)
repeat
local distance = (point - TheFirst.Parent.Torso.Position).magnitude
wait()
until distance < 3
end
end)
- Change TheNpc to your npc's name
- Make two bricks in the workspace , one called FirstBrick (Start point) and another one called SecondBrick (FinishPoint)
3)Make a brick in the workspace called Click, with a click detector inside.
- Place the script in the workspace.
TIP: The npc will take the fastest way to the finish point.
If that doesn't work check: http://wiki.roblox.com/index.php?title=Pathfinding
2 comments
how is moveto being called is it from the player clicking on the game world? or is the player being moved after an event what?
I want to call it when the intvalue of the rock's position changes