AI Pathfinding (Help)

I wrote an AI Pathfinding script. It is working as intended and everything, but I don’t understand the point of the wait that we have to add(The code in the red box). If someone could explain this to me, I would be grateful. Thank you.
AIPathfindingscript

Did u anchor the humanoid root part?

If so please unanchor it. 30 charsss

And i also suggest not inserting a brick through a script

Hey! As I have mentioned in the description, the code is working as intended. Its just the wait that i’m confused about.

The function :Wait() waits for an event to happen only once.

If you put a :Wait(2) then it will wait for the event to fire. Apparently there used to be a difference with :Wait() to :Wait(n) but today there is none.

local timeout = Hum.movetofinished:Wait(2) --Waits until the event fires

1 Like

Oh! So it waits 2 seconds for it to move to the next waypoint?

Pretty much, but if it finishes before 2 seconds it will stop waiting.
If it takes longer than 2 seconds it will stop waiting as well.
Look at my edit in the original comment for why you need this :slight_smile:

Edit: that was how it used to work, now there is no difference between :Wait() and :Wait(n). It will wait forever.

1 Like

I just checked RBXScriptSignal
and did an experiment right now, “Events” as far as I know do not have a timeout.

This means that the script will yield until that event is fired and will not automatically resume after 2 seconds have passed.

Edit: Video proof

Having scripted AIs, I can tell you this is not the case.
:Wait() with nothing in it would yield until the event is fired.

:Wait(n) with a number in it would wait; and return false if n time passes before the event fires.

About the video proof, your humanoid is in serverstorage and you didn’t start the event. I will do my own experiment as well :)))

EDIT: This is how it used to work, not any more :frowning:

I got the same thing. Interesting, as it worked for me the last time I used it. Do you know if an update changed it?

I don’t think any new update was made to events, and It makes sense as :Wait() is essentially :Connect() but the thread yields till the event is Fired instead.

Also, I would recommend not deleting comments if you get something wrong, it’s helpful to others who have similar questions.

EDIT: you should probably also edit your solution, as it contains misinformation

1 Like

I must say, the devforum is extremely helpfull. Thanks you all.