Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Npc humanoid not moving to position?

This is my code for my NPC Boss to move to where the player is but no errors show up in the output and the NPC doesn't move even though it's getting a position to go to. Help? Edit: Some variables were named wrong. Still doesn't move though.

local function moveToTarget(target)
	if not target then return end
	newPath:ComputeAsync(Torso.Position, target.Torso.Position)
	waypoints = {}
	if newPath.Status ~= Enum.PathStatus.Success then
		bossHumanoid:MoveTo(Torso.Position)
		return
	end
	waypoints = newPath:GetWaypoints()
	pathIndex = 1
	bossHumanoid:MoveTo(waypoints[pathIndex].Position)
	PlayAnimations(2, Enum.AnimationPriority.Movement)
	idlingAnim:Stop()
	local connection
	connection = bossHumanoid.MoveToFinished:Connect(function(reached)
		if reached then
			if target.Torso.Position == waypoints[#waypoints].Position then
				if pathIndex < #waypoints then
					pathIndex = pathIndex + 1
					bossHumanoid:MoveTo(waypoints[pathIndex].Position)
				end
			else
				newPath:ComputeAsync(Torso.Position, target.Torso.Position)
				waypoints = newPath:GetWaypoints()
				pathIndex = 1
				bossHumanoid:MoveTo(waypoints[pathIndex].Position)
			end
		end
		connection:Disconnect()
	end)	
	local blockConnection
	blockConnection = newPath.Blocked:Connect(function(blockedIndex)
		if blockedIndex >= pathIndex then
			newPath:ComputeAsync(Torso.Position, target.Torso.Position)
			waypoints = newPath:GetWaypoints()
			pathIndex = 1
			bossHumanoid:MoveTo(waypoints[pathIndex].Position)
		end
		blockConnection:Disconnect()
	end)
	
	if blockConnection then
		blockConnection:Disconnect()
	end
	if connection then
		connection:Disconnect()
	end
end

1 answer

Are you sure it's unanchored? :D

2 comments

0

It is unanchored and I tested MoveTo() in the script and it moves regularly in a straight line

0

but won't work from some reason when i try to make it move to one of the points in the path

This discussion is preserved as it was. New answers, comments, and votes are closed.