I’m making an optimizer plugin, and I need to check if any scripts contain wait() and recommend to change them to task.wait(). How could I do this? I tried using string.find(Script.Source, 'wait%('), but that gives a false positive when scripts use task.wait(), and WaitForChild if it’s lowercase.
I also tried using the ^ magic character at the beginning of the find pattern, but that only works if the script’s first line is wait().
Any ideas? Is there another magic character that could help out here?
local beg = string.find(Script.Source, 'wait%(')
local beg2 = string.find(Script.Source, 'task%.wait%(')
if beg and (not beg2 or beg2 and beg ~= beg2+5) then
--recommend
end
Sorry for the messy script. I edited a few things that I added and weren’t needed.
Edit: Okay, maybe it was needed. Edited the script again
An important note to other people doing this, though: If you are looping through game, it will also detect CoreGui, so you will have to individually loop through every common service. I did this by using CombinedPairs:
for _, Script in CombinedPairs(dsc(game:GetService('ReplicatedStorage')), dsc(game:GetService('Workspace')), dsc(game:GetService('Lighting')), dsc(game:GetService('ServerScriptService')), dsc(game:GetService('ServerStorage')), dsc(game:GetService('StarterPack')), dsc(game:GetService('StarterPlayer')), dsc(game:GetService('StarterGui')), dsc(game:GetService('ReplicatedFirst'))) do
It’s obviously… a little messy… but it does the trick.