I checked the pathmesh for my game and it turns out that there is no purple mesh over my game. is there anyway to fix this? I also checked another game of mine and I could see the mesh for that one just fine.
local NPC = script.Parent -- set to the directory of your npc
local PathFindingService = game:GetService('PathfindingService')
local pathParams = {
["AgentHeight"] = 15, -- height of your npc
["AgentRadius"] = 4, -- radius of your npc
["AgentCanJump"] = false -- whether it can jump or not
}
local Path = PathFindingService:CreatePath(pathParams)
local function GetDestination()
local Waypoints = game.Workspace.Waypoints-- change to where your positions are
local ChosenWaypoint = Waypoints:GetChildren()[math.random(1,#Waypoints:GetChildren())]
return ChosenWaypoint
end
local function Patrol()
local Destination = GetDestination()
if Destination then
Path:ComputeAsync(NPC.HumanoidRootPart.Position,Destination.Position)
local Waypoints = Path:GetWaypoints()
if Path.Status == Enum.PathStatus.Success then
for Index, Waypoint in pairs(Waypoints) do
if Waypoint.Action == Enum.PathWaypointAction.Jump then
NPC.Humanoid.Jump = true
end
NPC.Humanoid:MoveTo(Waypoint.Position)
NPC.Humanoid.MoveToFinished:Wait()
end
else
warn('Unable to make a path')
end
else
warn('No Destination')
end
end
while wait(0.25) do
Patrol()
end
Thank you for the advice, however from what I am experiencing, I believe there is a problem with my map as to where path finding service does register anywhere on my map as path, and that is why my script does not work. If possible I would like to figure out the cause of that problem. I will definitely learn and take from your script however.
As it turns out, after checking my game again, There was a humanoid Parented to the workspace which was messing with the pathfinding, Thank you everyone for the advice andsupport