How can i make a looping ai

hey i need help with an ai im trying to make its going to be a guard that loops around an item searching for the player but i can only make it go to one point that doesnt loop can anyone help me with making it loop around an item

Could you show your attempted script in making an AI?

You can make a folder with bunch of ordered parts and use a for loop to iterate over that folder and move to every part. You can put all that code into a function and run that function indefinitely. If the item you want the guard to loop around is in a variable position then you gotta do pathfinding to reach the item and make an algorithm to create the ordered parts around the item (using vectors ofc.) in a folder, and run the function in a loop as long as you make sure the item’s position isn’t changing…Otherwise do pathfinding again…etc… This is one way of doing it I
suppose. It can get much more complex if path was blocked or the ai got stuck you need to be able to handle these situations…

EDIT: I didn’t take into account that you gotta be searching for players, more work to add into the ai during the pathfinding and the circulation around the item.

Here’s some pseudocode on how to do this loop:

while true do
    local target = FindTarget()

    if target then
        WalkTo(Target)
    else
        LoopThroughParts()
    end
    task.wait(.05)
end