Advertisement
IHATEMICROWAVEOVEN

ez wait

Apr 3rd, 2022
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. local o_clock = os.clock
  2. local c_yield = coroutine.yield
  3. local c_running = coroutine.running -- note for line 9:
  4. local c_resume = coroutine.resume -- identical to "for Idx, data in pairs(Yields) do"
  5.  
  6. local Yields = {}
  7. game:GetService('RunService').Stepped:Connect(function() -- every frame it runs this:
  8. local Clock = o_clock() -- the curtime is saved, with high precision (micro)
  9. for Idx, data in next, Yields do -- let's check on all the waits right now:
  10. local Spent = Clock - data[1] -- the elpsdtime is set to curtime minus starttime
  11. if Spent >= data[2] then -- if the elpsdtime achieves the waittime, then:
  12. Yields[Idx] = nil -- clear the sent data
  13. c_resume(data[3], Spent, Clock) -- resume the running function
  14. end -- end
  15. end -- end
  16. end) -- end
  17.  
  18. return function(Time)
  19. Time = (type(Time) ~= 'number' or Time < 0) and 0 or Time -- if given a bad time value, it doesn't wait
  20. table.insert(Yields, {o_clock(), Time, c_running()}) -- sends the starttime, waittime, and running function
  21. return c_yield() -- stops the running function
  22. end
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. Some more info (not part of the code):
  31. Heya. This is a module for Luau (i.e. Roblox) that optimizes the wait() command. All of these lines of code were written by Pyseph, but I have marked them up for personal viewing. Here is where I found this:
  32. https://devforum.roblox.com/t/custom-wait-the-best-solution-to-yielding/715274
  33. Again, I didn't write this. This is Pyseph's work.
  34.  
  35. Suerte!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement