AI stuttering Help

So im scripting ai for my new game but the ai is very buggy idk why

local function FindAnyPlayers(Distance)
	local players = Players:GetPlayers()
	local nearestDistance = Distance
	local nearestPlayer = nil
	for index, player in pairs(players) do
		if player.Character then
			local target = player.Character
			local distance = (Wendigo.HumanoidRootPart.Position - target.HumanoidRootPart.position).Magnitude
			if distance < Distance then
				if distance < nearestDistance then 
					nearestPlayer = player 
					nearestDistance = distance 
					end
				end
			end
		end
		return nearestPlayer 
	end

while wait(0) do
	local Target = FindAnyPlayers(300)
	if Target == nil then
	else
		FindingPlayyer:Run(Target.Character.PrimaryPart.Position)
	end
end


Why you trying get nearest player from :GetPlayers()? Try workspace:GetChildren() and for find player do if v:IsA("Model") and v:FindFirstChild("Humanoid") And your 2. mistake is what is :Run()? You should make a follow script with NPCHumanoid:MoveTo(target)

One using GetPlayers is more efficent because your always going to get the player, and not npc’s. And second Im using :Run because its from a pathfinding module

Then problem is about pathfinding. There’s nothing wrong I see.

For a custom humanoid, make sure to change the agent parameters to get the best-generated path based on the humanoid.


How to pass in the agent parameter (see constructor in api): GitHub - Zeref-Z/RBLX-SimplePath: SimplePath is an open-source pathfinding module that gives you the ability to quickly create a pathfinding script for humanoids and non-humanoids with just a few lines of code.

Calculating agent parameters: Calculating Agent Parameters for PathFindingService? - #2 by Corecii

List of agent parameters: PathfindingService | Roblox Creator Documentation

well, i used it on a r15 dummy but still did the same thing

this is right, but you can always use :GetPlayerFromCharacter() if you don’t want npcs

there is one slight problem with :GetPlayerFromCharacter() because it isn’t thread safe, so :GetPlayers() is better due to that reason

Not sure what you mean but rig type doesn’t matter when setting agent parameters.

Im saying its not the agent parameters because the same problem still happens on a r15 rig :