NPC wont move away from the player?

Wrote a quick function to detect if a player is close to the NPC, but the ‘parasite’ does not move away from the player ! Looking for a quick fix and understanding to this, please LMK anything!

local function Acknowledge(Parasite)
	local closestHumanoid
	local ParasiteMinRange = Parasite:GetAttribute("minRange")
	
	for i, part in ipairs(workspace:GetChildren()) do
		if part:IsA("Model") then
			local humanoid = part:FindFirstChild("Humanoid", 2)
			
			if humanoid and part:HasTag("Parasite") == false then
				
				local distance = (Parasite.PrimaryPart.Position - part.PrimaryPart.Position).Magnitude
				
				if distance < ParasiteMinRange then
					closestHumanoid = humanoid
					
					local path = pathfindingService:CreatePath()
					local direction = (Parasite.PrimaryPart.Position - part.PrimaryPart.CFrame.LookVector).Unit
					local destination = Parasite.PrimaryPart.Position + direction * 15
					
					print(destination)
					
					path:ComputeAsync(Parasite.PrimaryPart.Position, destination)
					
					local waypoints = path:GetWaypoints()
					
					if #waypoints > 0 then
						Parasite.Humanoid:MoveTo(waypoints[1].Position)
					end
					
				end
			end
		end
	end

	return closestHumanoid
end

The parasites themselves,
image

I am not getting any errors in my output, it actually seems to work fine, but my parasites refuse to move??

1 Like

You should check more documentation and posts of how to use the waypoints.
You should move the character on a loop iterating the waypoints, you got a list of waypoints when you used ComputeAsync, and then you can use them with :GetWaypoints()
So you can use each point to apply MoveTo and depending on the result of that method your code should decide if move to next or any behavior that you desire

1 Like

You are sure you read the code yes?

She has a point, though. GetWaypoints in simple terms, gives out the steps the character should take in order to reach the intended destination. The fact that you chose the first index in the returned table means the trajectory is incomplete. Also, I’ve been wondering this, but shouldn’t this Acknowledge function be run in a loop? After all, if the player moves, the path will be guided to an outdated position. That’s the logic used in normal player-tracking scripts, but I’m not really experienced with path finding yet, so this could turn out to be incorrect.

The function is called constantly in a function, might change it, just trying to solve this first issue first, and I am aware what GetWaypoints(), as a matter of a fact, it did work once, so im not sure if its an issue with the physical character.

Not an issue with the character, regular rigs wont move either.

Say, can you even call FindFirstChild with a number parameter? Referring to the

local humanoid = part:FindFirstChild("Humanoid", 2)

part.

According to the documentations, the second parameter should be a boolean, not an integer.

If this is not the issue, then maybe some conditions aren’t being met. Try placing prints after the if statements, for debugging purposes. If not even this, it is most likely a logic issue (the math to calculate the destination), though I wouldn’t be able to tell since I’m not good with CFrames / Vectors.

Oh, forgot I added that, but the script hasn’t had any issues with having that.

Also the waypoints work completely fine, the primary issue is that characters will not move.
image

DID NOT fix it.
(Nevermind, He still refuses to move)

ok i fixed it??

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.