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