Hello, i am making a pretty simple AI and im trying to make it so it wander around a point and when a player is close enough, it walks towards the player, that part is working, only, when it is stopped on a spot while "wandering" there is a random wait time (5,10) and it wont start following the player because it is waiting for this to finish, how can i make it break its waiting time when the player is close enough?
while true do
wait(.5)
local target = findNearestTorso(script.Parent.Torso.Position)
local torso = script.Parent.Torso
local dist = (torso.Position - point.Position).Magnitude
if target ~= nil and dist < (math.random(30,35)) then
script.Parent.Humanoid.WalkSpeed = 15
script.Parent.Humanoid:MoveTo(target.Position, target)
else
script.Parent.Humanoid.WalkSpeed = 10
script.Parent.Humanoid:MoveTo(Vector3.new(math.random(point.Position.x-15,point.Position.x+15),0,math.random(point.Position.z-15,point.Position.z+15)), point)
if target == nil then
wait(5,10) --[[HERE]]
end
end
end

1 comment
thanks! just had to remove the lines 12 to 14 and it worked perfectly!