#Pathfinding script not working

7 messages · Page 1 of 1 (latest)

honest talon
#
script.Parent.HumanoidRootPart:SetNetworkOwner(nil)
script.Parent.PrimaryPart:SetNetworkOwner(nil)
task.wait(1)
local players = game:GetService("Players")
local distance
local pfs = game:GetService("PathfindingService")

local function nearestPlayer()
    for _, player in ipairs(players:GetPlayers()) do
        local distance = (script.Parent.HumanoidRootPart.Position - player.Character.PrimaryPart.Position).Magnitude
        local distanceMax = math.clamp(distance, 0, 100)
        if distance > 100 then
            local path = pfs:CreatePath({
                AgentHeight = 5;
                AgentRadius = 2;
                AgentCanJump = false;
                AgentCanClimb = false
            })
            path:ComputeAsync(script.Parent.HumanoidRootPart.CFrame, player.Character.HumanoidRootPart.CFrame)
            local waypoints = path:GetWaypoints()
            for _, waypoint in ipairs(waypoints) do
                script.Parent.Humanoid:MoveTo(waypoint.Position)
            end
        end
    end
end

while task.wait() do nearestPlayer() end

So the problem seems to come from this part ```lua
local distance = (script.Parent.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).Magnitude

pure lion
#

use if statement to see if character and humanoid root part exist

tender thicket
#

That's just a stupid thing that Roblox has

#

Also you need to define "player"

#

You've defined "players" but not "player"

honest talon