How to add a wait() that doesn't hold up the rest of my function?

Hello, I know the title might suck but I can explain it much better here.

I have a long function with a lot of parts that flow in a certain order. In the beginning of it I have it change an announcement value in rep. storage in order to show an announcement to each of the players. Then ideally I’d add a wait() into it, then clear the value to take the message off, but it will halt the rest of the function from running until that wait is up. Is there a way I can make the function continue but have the one line wait? Does this make sense? I technically could just put the wait in the localscript that changes the actual GUI but that would mess a lot of things up. I will end up doing that if there is no other possible way.

Roblox’s built-in spawn and delay functions can achieve this. You should, however, ideally use the delay function (especially if it’s something as simple as clearing the announcement).

If you want to learn more about creating separate threads on Roblox, then coroutines would be something of interest.

Read these for further information and research on coroutines:

1 Like

This is exactly what I was looking for. Thank you!