function Pathfinding:CreatePath(Goal,PathInfo)
local Path = PathfindingService:CreatePath(PathInfo)
local Character = self.Character
local success, err = pcall(function()
Path:ComputeAsync(Character.PrimaryPart.Position,Goal)
end)
local Humanoid = Character:WaitForChild("Humanoid")
if success and Path.Status == Enum.PathStatus.Success then
local waypoints = Path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Walk then
Humanoid:MoveTo(waypoint.Position)
Humanoid.MoveToFinished:Wait()
elseif waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
end
else
warn(err)
end
end
You should be calling it on every BasePart on every frame, like so:
RunService.Heartbeat:Connect(function()
for _, v: BasePart in pairs(self.Character:GetDescendants()) do
if v:IsA("BasePart") and v:CanSetNetworkOwnerShip() then
v:SetNetworkOwner(nil)
end
end
)
You’re also calling the wrong function. You want to call SetNetworkOwner(nil). Hope this helps you out!
pathfinding is a bit laggy/buggy if run on a loop, to detect if it’s on a loop just print(“E”) or something to be 100% sure it’s not. If you want it to be on a loop you gotta be smart about it, and make like a wait(1) or an alternating follow/pathfind script (If there’s a bunch of moving parts)
Set all the parts of the NPC’s network owner to the first player that joins.
game.Players.PlayerAdded:Wait()
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then
v:SetNetworkOwner(workspace:WaitForChild(game.Players:GetPlayers()[1].Name))
end
end