I’m making a piggy style game, and I have an AI script I made myself, but the monster completes its entire path before updating and re-routing to track the player again.
I’ve tried everything I could think of, but I can’t get it to work no matter what I do.
How would I timeout a MoveToFinished?
Here’s the pathdfinding Code -
local function walkTo(target)
local path = getPath(target)
if path.Status == Enum.PathStatus.Success then
for index, waypoint in pairs(path:GetWaypoints()) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
if target:FindFirstChild("Humanoid") and target:FindFirstChild("Humanoid").Health > 0 then
if CanSeeTarget(target) then
humanoid:MoveTo(target.HumanoidRootPart.Position)
sunny.Eyes.Color = sunny.GlowingEye.Color
sunny.Eyes.Material = Enum.Material.Neon
break
end
humanoid:MoveTo(waypoint.Position)
sunny.Eyes.Material = eyeMaterial
sunny.Eyes.Color = eyeColour
humanoid.MoveToFinished:Wait()
end
end
end
end
local function patrol()
local target = findTarget()
if target then
walkTo(target)
target = findTarget()
end
end
while true do
patrol()
end