This is just a block of code that scripters will find very useful if you ever need to wait or yield for a shorter period of time than a 60th of a second. You will also find it useful if you need a much more accurate and consistent yield than that of the wait() method.
Make sure this code is put in a local script that is only run once, like a playerscript. It binds functions to renderstep so if the script is ran multiple times it will cause issues.
Simply call _G.AccuWait() instead of wait() in your scripts once this is in place. Itâs a global function, so all localscripts will be able to call it once itâs running.
This code is really helpful for fast operations. For example calling wait(0) is only waiting for 0.03 seconds. You could call RenderStep:Wait(). But at best youâll only yield for 0.0167 seconds, and if the user isnât running at 60 FPS itâll be longer.
The AccuWait function offers waits as short as 0.00167 seconds, and it rounds duration down if the user is at lower framerates.
local function StepMarker() FasterStep:Fire() end
for i =1,10 do
local val = Enum.RenderPriority.Camera.Value - 50
if i >= 5 then val = Enum.RenderPriority.Camera.Value + ((i-5)*10) else val = Enum.RenderPriority.Camera.Value - ((6-i)*10) end
RunService:BindToRenderStep("StepMarker"..i, val, StepMarker)
end
local function GetSteps(Duration)
local StepTime = RSTime/10
local steps = math.floor(Duration/StepTime)
return steps
end
function _G.AccuWait(Duration) --This is the function to call
if Duration == nil then Duration = RSTime/10 end
local steps = GetSteps(Duration)
if steps > 1 then
for i = 1,steps do
FasterStep.Event:Wait()
local newsteps = GetSteps(Duration) if newsteps < steps and i >= newsteps then break end
end
else
FasterStep.Event:Wait()
end
end
RunService.Heartbeat:connect(function(step) RSTime = step end)