I have read quite a few forum posts from people who strongly recommend to avoid using wait. Mainly claiming performance issues or some other things. But there are also people who say the opposite and that there is no problem with wait, which leaves me completely confused.
There is also the fact that roblox is constantly being updated and improved leaving many of the past opinions obsolete. For example, this is what it says in the documentation:
Roblox’s thread scheduler is exposed through the functions spawn(), wait(), and delay(). These actually work using coroutines.
My question is, with everything said above, should I really avoid using wait nowadays? And does the fact that wait works with corrutines really prevent me from having the problems people claim?
You should just avoid using wait() excessively. If you over use wait() (for example, having every part have a while wait() do loop) you can stop spawn(), delay(), and a bunch of other things from working.
I find that wait(n) is fine if you’re purposefully implementing a pause in the game (like a 15 second intermission or something). Wait() is really only problematic when you use it too much at one time, like during a while or for loop.
It’s still a perfectly fine up to date resource. Two years really isn’t that much time; Roblox hasn’t made any significant, visible changes to how their task scheduler works since then.
Alright, since you have been reading, you probably have noted that, this functions performance impact is almost null, pretty small, that would change nothing, many popular games still use this functions…
Using them will not be bad, and the performance impact will be as said before, almost null.
Though, if you really would like to not have any performance impact, there’s a bunch of ways you can achieve this, as making your own wait() function, or using runservice.
Nothing is wrong with wait. It’s how you use it that can potentially end up being a problem.
For instance, someone may do
local Players = game:GetService("Players")
local player = Players.LocalPlayer
wait()
local character = player.Character
It may work a couple times in Studio, but isn’t guaranteed to work 100% of the time. To 100% guarantee that character will always be correctly, you shouldn’t use wait. Instead
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()