A way to run a script above 60 Hz?

I’m looking for a way to loop more than just every frames…
For example, looping at 480 Hz, for that we could do that

while game:GetService("RunService").RenderStepped:Wait() do
    for i=0,8 do
        --code
    end
end

This would work but the wait until next loop is about >0 ms , I would like a wait of about ~20.833 ms

If you don't understand what I'm talking about

A loop of 60Hz (one loop per frame) would have two loops spaced of about ~166,667ms (1/60)
You can achieve that with

while game:GetService("RunService").RenderStepped:Wait() do
    --code
end

A loop of 480Hz (8LPF) should have two loops spaced of about ~20.833ms (1/480)
I’m looking for a way to achieve that

3 Likes

Why do you want a loop to run above 60 Hz?
What is your use case going to be?

If I am understanding you correctly you essentially want to know if you can run loops faster. I don’t think running loops faster is possible at the moment but it may be possible in the near future:

1 Like

In fact, I’m looking for a way to do something like that:

while true do
    wait(1/480) -- ~20.833ms
  --code
end

This should loop at 480Hz

local perfectDelta = 1/480
local runTimeStack = 0
local realTimeStack = 0

runService.WhaterverStep:Connect(function(realDelta)
	realTimeStack = realTimeStack + realDelta

	while realTimeStack >= perfectDelta do
		runTimeStack = runTimeStack + perfectDelta
		realTimeStack = realTimeStack - perfectDelta

		step(runTimeStack, perfectDelta)
	end
end)

if step() were just a print function you’d end up with:

1/480, 1/480
2/480, 1/480
3/480, 1/480
4/480, 1/480
...

would result in whatever step function essentially thinking it’s running at 480 hz since it’s localized time and time delta values reflect that.

I gotta ask though, why do you need to run anything this fast? I can’t say I’ve ever had a need to run something fast and out of sync with other game events/loops.

1 Like

I need things to go very fast because I need to do some test with sounds…
In reallity, 480Hz isn’t very fast, but it can be usefull…

If I want to slow down or lower volume smoothly (or custom)

What is rate?
It’s not defined

But couldn’t one achieve that with TweenService ?

it should per perfectDelta, sorry

Ok, I’m testing, if it works…

It works at the good frequency… But the wait time between two loops isn’t constant
It waits for 160ms then 0.7µs seven times then waits for another 160ms then 0.7µs seven times over and over…

Yes you can actually. I believe that characters run at aproximately 120 or 240 Hz. This isn’t a real framerate boost since it’s basically running the same code in bursts each frame.

local FRMultiplier = 4
game:GetService("RunService").HeartBeat:Connect(function(delta)
    delta = delta/FRMultiplier
    for i=1,FRMultiplier do
        --code
    end
end

Sadly, there is no way to really increase your framerate without framerate unlockers, but those can get you banned.

@waterrunner
Faster Lua =/= faster loops.
That update means that your code will execute with much less CPU usage.

@LMH_Hutch
You overcomplicated things.

2 Likes

Your script is almost like

But with 4 instead of 8

You are saying what I want to remove, it runs the same code 4 times in the same frame, but in a “burst”…

True… (SMILE)
Sorry for him

That’s the closest you can get to a higher frame rate in Roblox. I really don’t see why you would want something like this, unless you want to achieve something not related to games. Roblox can’t render a frame faster than 60 times a second anyways and physics probably won’t get much better from a higher FPS, unless you are working with integrations such as Euler or Verlet, but then it doesn’t need to be with equal deltas, just stable enough not to freak out.

It’s not relly for games, but if it works, I can use for games…
It’s more to make customs sounds envelopes…
It need faster frenquency than 60Hz but if I can do 480Hz, it must but at a stable waiting time

RenderStepped and even Heartbeat should be good enough for that. Just add some smoothing to avoid pops and other artifacts.

But how do we add smooth volume in sounds?

You’re probably trying to change the properties of a sound on the fly to follow a wave. Check if the sound decays or rises way too much to the point where it causes issues and decrease the difference between the 2 points.
If the individual effects are static, you could generate an array of numbers and smooth them out.

2 Likes

there is nothing overcomplicated about what I posted? If anything it’s more accurate to 480hz too since 4/delta can be a wildly different rate than 1/480. Accuracy at numbers that small matters.

1 Like

It’s like that… But said in another way…