How to stop Humanoid:MoveTo()?

I’m trying to make a bot for my game, when the player walks too close to the bot I want the bot to stop. I’ve tried moving the humanoid to its humanoidRootPart, it just starts spinning around endlessly. How could I do this? This is my script:

module.playerFound = function(botCharacter) -- this runs when the player is too close to the bot
	local humanoid = botCharacter:FindFirstChildOfClass("Humanoid")
	local humanoidRootPart = botCharacter:FindFirstChild("HumanoidRootPart")
	if humanoid and humanoidRootPart then
		print("Move")
		humanoid:MoveTo(humanoidRootPart.Position) -- this is it moving to its self
		humanoid.WalkToPart = humanoidRootPart
		humanoid.WalkToPoint = humanoidRootPart.Position
		humanoid.MoveToFinished:Wait()
		print("Moved") -- both of these print right after each other
	end
	return
end

robloxapp-20210226-2020266.wmv (255.3 KB)

2 Likes

You can use a MoveTo() on the bot at the position of the bot, and since its already at that position it will stop moving.

5 Likes

Yes, that is what I just did .

May not be too efficient, but:

while wait() do
if (botCharacter.Position - player.Character.Humanoid.Position).magnitude >= 2 then -- Change the "2" accordingly
botCharacter.Humanoid.WalkSpeed = 0
end
2 Likes

I want to actually stop the MoveTo function, wont this just stop them from moving then they would just resume walking afterwards.

instead of “WalkSpeed” try:

botCharacter.Humanoid:MoveTo(Vector3.new(0,0,0))
2 Likes

That just makes it move back to 0, 0, 0 in the middle of the map.

4 Likes

I have one more solution however it only freezes the Humanoid:

botCharacter.Humanoid.PlatformStand = true
1 Like

Does it cancel the Humanoid:MoveTo()?

Are you sure this doesn’t work? I used it on my NPCs too and it works fine. Also there’s no need to set all the properties (WalkToPart and WalkToPoint), MoveTo() will be enough.

1 Like

It does, but the bot spins around endlessly.

I’ll try on Studio in an empty project, hold on.

1 Like

No, sorry, it only stops the Humanoid from any type of movement.

1 Like

When I dont set the WalkToPart it wont work so Idk

https://gyazo.com/8db7ef95717178c95dc973374676589b
This works so if the NPC is too close to the player, it stops moving by using NPC.Humanoid:MoveTo(NPC.PrimaryPart.Position).

Then set the WalkToPart property only, as it automatically sets the other two by the part’s position.

2 Likes

Aha, I think I know why it isn’t working. It works (kinda) if I do this:

while wait() do
	humanoid:MoveTo(botCharacter.PrimaryPart.Position)
	humanoid.MoveToFinished:Wait()
end

Heres the script that actually tells the player to move to a part.

local waypoints = path:GetWaypoints()
	for index, waypoint in pairs(waypoints) do
		if waypoint.Action == Enum.PathWaypointAction.Jump then
			humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		end
		humanoid:MoveTo(waypoint.Position)
		humanoid.MoveToFinished:Wait()
	end

I think this is interfering with me trying to walk it to the humanoidRootPart, because it goes through the waypoints and so when I try to Humanoid:MoveTo(humanoidRootPart.Position) it doesnt work because it just goes back to the next waypoint. How would I fix this tho?? @AndroidBoyz

Just do:

Humanoid:MoveTo(botCharacter:FindFirstChild(“HumanoidRootPart”).Position)
1 Like

try with
humanoid:MoveTo(humanoidRootPart.Position)

Yeah, thats what I said I did.

local part = Instance.new("Part")
part.Name = "StoppingPart"
part.Anchored = true
part.Transparency = 1
part.CanCollide = false
part.Parent = workspace
part.CFrame = CFrame.new(botCharacter:FindFirstChild(“HumanoidRootPart”).Position)

Humanoid:MoveTo(part.Position)
Humanoid:MoveToFinished:Wait()
part:Destroy()