Why is my character standing in place?

I need my character to run after the closet player. But he moves and the animation is playing, but he refuses to run. What can is going on?

Script:

local function moveNPCCharPos() -- Moves Boss to Random Characters Position
	local NPC = game.Workspace["Sand Boss"]
	local pathfinding_service = game:GetService("PathfindingService")

	local function getClosestPlayer()
		local closest_player, closest_distance = nil, 200
		for i, player in pairs(workspace:GetChildren()) do
			if player:FindFirstChild("Humanoid") and player ~= NPC then
				local distance = (NPC.PrimaryPart.Position - player.PrimaryPart.Position).Magnitude
				if distance < closest_distance then
					closest_player = player
					closest_distance = distance
				end
			end
		end
		return closest_player, closest_distance
	end

	while true do
		local path = pathfinding_service:CreatePath()
		local player, distance = getClosestPlayer()
		if player and distance > 10 then
			path:ComputeAsync(NPC.HumanoidRootPart.Position, player.PrimaryPart.Position)
			local waypoints = path:GetWaypoints()
			for _, waypoint in pairs(waypoints) do  
				NPC.Humanoid:MoveTo(waypoint.Position)
				while true do
					local distance = (NPC.PrimaryPart.Position - waypoint.Position).Magnitude
					local distance_from_player = (NPC.PrimaryPart.Position - player.PrimaryPart.Position).Magnitude
					if distance < 5 then
						break
					end
					if distance_from_player < 10 then
						NPC.Humanoid:MoveTo((NPC.HumanoidRootPart.CFrame*CFrame.new(0,0,-3)).p)
						break
					end
					wait()
				end
			end
		end
		wait()
	end
end

I dont understand what you mean by now can you send a video?

The animation is playing but he doesnt run like I said.

1 Like

on this part
if distance < 5 then
break
end
i think this might be a problem

1 Like

Hmm, I would say that the dummy is anchored but I do not think that is the problem. This might help in trying to find the resolution to the problem. BodyMover | Roblox Creator Documentation

I disabled that portion of the script and if you go near the NPC, he moves very choppily. If I go away, the same problem persists.

I dont think BodyMovers are necessary for character movement…

use a movetofinished:Wait(2) this might work

Where would I place this? (char)

in the loop, this function is used for checking if the NPC is moved to the finished
after waiting 2 second it will run a next line

It doesnt work stil :c

i love roblox

try changing humanoid walkspeed

if the character is too big, it will walk slow

No it doesnt move at all when adding the line.

if player and distance > 10 then
so the reason he didnt move is because the distance of closet player is less than 10
this might be a reason

Try this:

local NPC = game.Workspace["Sand Boss"]
NPC.PrimaryPart:SetNetworkOwner(nil)

local function moveNPCCharPos() -- Moves Boss to Random Characters Position
	local pathfinding_service = game:GetService("PathfindingService")

	local function getClosestPlayer()
		local closest_player, closest_distance = nil, 200
		for i, player in pairs(workspace:GetChildren()) do
			if player:FindFirstChild("Humanoid") and player ~= NPC then
				local distance = (NPC.PrimaryPart.Position - player.PrimaryPart.Position).Magnitude
				if distance < closest_distance then
					closest_player = player
					closest_distance = distance
				end
			end
		end
		return closest_player, closest_distance
	end

	while true do
		local path = pathfinding_service:CreatePath()
		local player, distance = getClosestPlayer()
		if player and distance > 10 then
			path:ComputeAsync(NPC.HumanoidRootPart.Position, player.PrimaryPart.Position)
			local waypoints = path:GetWaypoints()
			for _, waypoint in pairs(waypoints) do  
				NPC.Humanoid:MoveTo(waypoint.Position)
				while true do
					local distance = (NPC.PrimaryPart.Position - waypoint.Position).Magnitude
					local distance_from_player = (NPC.PrimaryPart.Position - player.PrimaryPart.Position).Magnitude
					if distance < 5 then
						break
					end
					if distance_from_player < 10 then
						NPC.Humanoid:MoveTo((NPC.HumanoidRootPart.CFrame*CFrame.new(0,0,-3)).p)
						break
					end
					wait()
				end
			end
		end
		wait()
	end
end

same result. Doesnt even try to move towards me

Get the lastest waypoint and move so it will be smooth
NOTE: im busy so i’ll write a code later

I already tried that. He wouldnt even move at all.

The walk animation run because the NPC is walking to somewhere
in your video the walk animation works but the NPC isnt running
so the script is working good but it have a problem on some where else?

Nope the other scripts i have arent the issue.