#Path always being successful even when it shouldn't be.
1 messages · Page 1 of 1 (latest)
local SCP = script.Parent
local PrimaryPart = SCP.PrimaryPart
local PathFindingService = game:GetService("PathfindingService")
local Path = PathFindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 0.64,
WaypointSpacing = 1,
costs = {
AvoidWallZone = math.huge
}
})
wait(3)
while true do
wait()
local TargetName = SCP:GetAttribute("ClosestPlayerName")
local Distance = SCP:GetAttribute("DistanceToTarget")
local Target = game.Workspace:FindFirstChild(TargetName).HumanoidRootPart
if Distance < 20 then
if Distance > 6 then
Path:ComputeAsync(SCP.PrimaryPart.Position, Target.Position)
local waypoints = Path:GetWaypoints()
for i, waypoint in waypoints do
local p = Instance.new("Part", workspace)
p.Position = waypoint.Position
p.Anchored = true
p.Material = Enum.Material.Neon
p.CanCollide = false
p.Size = Vector3.new(1,1,1)
end
for i, waypoint in waypoints do
wait()
SCP.Humanoid:MoveTo(waypoint.Position)
end
if Path.Status == Enum.PathStatus.Success then
for i, wapoint in waypoints do
SCP.Humanoid:MoveTo(wapoint.Position)
SCP.PrimaryPart.CFrame = CFrame.lookAt(SCP.PrimaryPart.Position, Target.Position)
end
else
warn("Path not possible")
end
end
end
end
"costs" needs to be capitalised. see the "key" section of the table in https://create.roblox.com/docs/reference/engine/classes/PathfindingService
theres a few other issues tho, the lag is probably because ur spawning those neon parts very frequently,
also, why are you calling MoveTo() in 2 diff loops
for i, waypoint in waypoints do
wait()
SCP.Humanoid:MoveTo(waypoint.Position)
end
if Path.Status == Enum.PathStatus.Success then
for i, wapoint in waypoints do
SCP.Humanoid:MoveTo(wapoint.Position)
SCP.PrimaryPart.CFrame = CFrame.lookAt(SCP.PrimaryPart.Position, Target.Position)
end
youre moving it the first time for each waypoint
and then youre moving it again if the path is a success
** You are now Level 1! **
cc @lapis tartan
Ah, I see.