My pathfinding agents decide to walk on the neon even though its material cost is higher?
local npc = script.Parent
local hum = npc:WaitForChild("Humanoid")
local walking = false
local debris = game:GetService("Debris")
local walkani = hum:LoadAnimation(npc.Animate.walk.WalkAnim)
local path = pathfindserv:CreatePath({
agentcanjump = true,
agentcanclimb = true,
agentradius = 15,
Costs = {
Plastic = 1,
Neon = 100,
},
})
while true do
if walking == false then
local goalpart = Vector3.new(math.random(-10,10),10,math.random(-10,10))
local success, error = pcall(function()
path:ComputeAsync(npc.HumanoidRootPart.Position, workspace.Area.Position - goalpart)
end)
if success and path.Status == Enum.PathStatus.Success then
local part = Instance.new("Part")
part.Anchored = true
part.Material = Enum.Material.Neon
part.CanCollide = false
part.Color = Color3.new(0, 1, 0)
part.Shape = "Ball"
part.Position = workspace.Area.Position - goalpart + Vector3.new(0,13,0)
part.Parent = workspace
debris:AddItem(part,3)
walking = true
walkani:Play()
for i,waypoints in pairs(path:GetWaypoints()) do
local part:BasePart = Instance.new("Part")
part.Material = Enum.Material.Neon
part.Anchored = true
part.CanCollide = false
part.Shape = "Ball"
part.Position = waypoints.Position
part.Parent = workspace
debris:AddItem(part,3)
hum:MoveTo(waypoints.Position)
if waypoints.Action == Enum.PathWaypointAction.Jump then
hum.Jump = true
end
hum.MoveToFinished:Wait()
end
walking = false
walkani:Stop()
else
warn("cantcreate")
end
end
wait()
end