A while back I created a system for accurate yielding. It was really broken, and showed that at the time I had little understanding of roblox task scheduling.
Now after lots of learning through experience, I’ve created a system that ACTUALLY yields more accurate than any system on roblox thus far. Even more accurate than the original wait(). This system is useful for waiting very short periods of time, or in situations where you need a wait more precise than a fraction of a frame length.
local RS = game:GetService('RunService') local OpTime = 0 local function OperationCheck() local st = tick() for k = 0,50 do local num = 4294967296 num = num ^ 0.5 if tick()-st >= 200 then break end end if tick()-st >= 200 then end OpTime = tick()-st end local FrameDelta = 0 RS.RenderStepped:connect(function(delta) FrameDelta = delta OperationCheck() end) OperationCheck() function RealWait(Duration) if Duration == nil then Duration = 0.1/3 end local st = tick() while tick()-st < Duration-FrameDelta-OpTime do RS.RenderStepped:wait() end local n = Duration - (tick()-st) for i = 0,n,OpTime do for k = 0,50 do local num = 4294967296 num = num ^ 0.5 if tick()-st >= Duration then break end end if tick()-st >= Duration then break end end end
Simply call RealWait like you would normal wait.
How does it work? Assuming your desired duration is longer than a single frame, the function will yield for that amount of time minus 1 framelength. Then for the last frame, it’ll use a for loop operation to stretch the last framelength to fill the desired duration. This means super accurate wait times even for users on the slowest of machines.