Yes, that is because of the 1 second delay, have you added the break condition to the PathFinding
so it stops tracking you?
if player then
playersInSafeZone[player.Name] = true
player.Character:SetAttribute(SAFE_ZONE_TAG, true)
print(player.Character:GetAttribute(SAFE_ZONE_TAG))
end
where do i add the break at
(30000000000000000000000)
Try this:
local function moveToTarget(enemy, target)
local path = PathfindingService:CreatePath()
path:ComputeAsync(enemy.HumanoidRootPart.Position, target.Position)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
enemy.Humanoid:MoveTo(waypoint.Position)
local reached = enemy.Humanoid.MoveToFinished
if not target:GetAttribute(SAFE_ZONE_TAG) then break end
if not reached then
print("Failed to reach waypoint")
break
end
end
else
print("Path computation failed:", path.Status)
end
end
since the attribute is originally set to false do i set it to true before chasing
because rn it won’t chase me because of the if statement
Just remove the not then:
local function moveToTarget(enemy, target)
local path = PathfindingService:CreatePath()
path:ComputeAsync(enemy.HumanoidRootPart.Position, target.Position)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
enemy.Humanoid:MoveTo(waypoint.Position)
local reached = enemy.Humanoid.MoveToFinished
if target:GetAttribute(SAFE_ZONE_TAG) then break end
if not reached then
print("Failed to reach waypoint")
break
end
end
else
print("Path computation failed:", path.Status)
end
end
it still goes inside(300000000000)
1 Like
what should i do(30000000000000000000000000000000)
Hey! I would like to tell you that I have fixed the problem! All I had to do was once the player enters the safe zone the ai would go to the last spot he was right before the player entered the safe zone
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.