Bot not reaching end part

Hello, I have scripted a bot to move towards and end part, but at somepoint during that it decides to stop instead of continuing to reach the part.

Screenshot 2022-07-29 135952

I have no idea what could be causing this, thank you for any help.

1 Like

can you show us your code?
[Char Limit]

local Noob = script.Parent
Noob.Humanoid:MoveTo(workspace.End.Position)

make sure both parts are anchored

or you can keep them unanchored but,
you can loop it so if the endpart’s position changes they will still go for it

local Noob = script.Parent
while wait(0.1) do
Noob.Humanoid:MoveTo(workspace.End.Position)
end

That worked, thank you very much for your time.

Just something to add here, Model:MoveTo() does NOT preserve rotation and is not safe to use in an unsynchronized thread. A better alternative to that is using Model:SetPrimaryPartCFrame.

And this little Jake is how to create memory leaks for your game. Why are you setting up this inefficient loop instead of using RunService.Heartbeat()?

oh ye mb @Walvolin here’s a better alternative way

local Noob = script.Parent

game:GetService("RunService").Heartbeat:Connect(function()
task.wait()
Noob.Humanoid:MoveTo(workspace.End.Position)
end)

and as @Kostiskat mentioned you can use SetPrimaryPartCFrame instead of Humanoid:MoveTo()

game:GetService("RunService").Heartbeat:Connect(function()
task.wait()

This is redundant.

while true do
	Humanoid:MoveTo(Vector3.new(0, 0, 0)) --Move humanoid to position inside of a while true do loop.
	Humanoid.MoveToFinished:Wait() --Wait for 'MoveToFinished' event/signal to fire before beginning the next cycle of the loop.
end

MoveToFinished will either fire when the humanoid reaches its destination or after eight seconds have elapsed since the call to MoveTo.