A way to run a script above 60 Hz?

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…

See that topic Is there a way to play Arrays as a PCM sample?

If I can change the volume of a soun on the fly, I would be able to use it in a game which will have computers that could run random/custom sounds made by players (or made by the script that players made)
The sounds will be moderated

You could try something similar to the FABRIK algorithm used in inverse kinematics. It makes multiple passes forth and back until a desired result is reached, or it goes through too many cycles.
Basically, if you had 10 points, you would first start from the point 2 and iterate through all of them but the last, checking if they are within limits and pulling them back to the max difference between points. Then you would do the same, but backwards and you repeat that multiple times.

I don’t know FABRIK but I think it’s not to do faster loops (LOL)
For sounds, it can be usefull

What I’m saying is that you can apply it to your use as a way to smooth out what would cause artifacts in sounds, since you can’t run them at higher frequency.

Yes… But if I can do that at higher frequencies, I won’t really need that… I don’t think…
So… How can we make a high frequency loop? (with stable frequency)

Now way to do that.
Here’s what I meant:

local cycles = 5
local maxdiff = 1
local function SmoothArray(arr)
	for i=1,cycles do
		local p0 = arr[1]
		for i=2,#arr-1 do
			local p1 = arr[i]
			if math.abs(p1-p0)>maxdiff then
				p1 = p0 + maxdiff*math.sign(p1-p0)
				arr[i] = p1
			end
			p0 = p1
		end
		local done = true
		local p0 = arr[#arr]
		for i=#arr-1,2,-1 do
			local p1 = arr[i]
			if math.abs(p1-p0)>maxdiff then
				p1 = p0 + maxdiff*math.sign(p1-p0)
				arr[i] = p1
				done = false
			end
			p0 = p1
		end
		if done then
			return
		end
	end
end
local TT=tick()
local FT=tick()

RS.RenderStepped:Connect(function()
	FT=tick()
	while tick()-FT<1/60 do
		while tick()-TT<1/480 do end
                TT=tick()
		--Code
	end
end)

This can work… But with waits too much between two frames…
It waits 130ms then ~20.8ms several times… Over and over…

1 Like

This will lag to much. Just try running while true do end. It’ll crash your studio.
Roblox can’t run loops without yields, and what you’re doing will lower the framerate to something around 20.

wait(interval) caps at like 0.03

1 Like

Yep. game:GetService(“RunService”).RenderStepped:Wait() will yield for up to 0.017 if there is no lag.

Define lag, if you mean lag by the huge latency between the client and the server, that is not linked with this case. If you by lag you mean frame drops then you are partially correct. game:GetService(“RunService”).RenderStepped fires every frame so if a client is running ROBLOX at like 40 FPS, the event will get fired 40 times a second.

I meant frame drops. RenderStepped and Heartbeat are only a good wait() replacement above 33 FPS.

game:GetService(“RunService”).Heartbeat is fired on every frame in the RunService. It is still not guaranteed that it will fire 60 times a second, also it can only be used from the server.

Heartbeat can be used on both client and server. It’s an event used for physical simulations as it fires after each frame, giving a wide time window for complex operations.

RenderStepped it fires before each frame is rendered. Since the server doesn’t have a display, this event only exists on clients.

Woops! Sorry for giving false information. I was pretty sure that it only ran in the server :thinking:.