Updating faster than RenderStepped or task.wait()

I have recently developed a way to updated something faster than 60/s

here you can see 8 evenly spaced increments (the red circles), each are events that any normal script can bind to allowing for 480/s or more

This can be incredibly useful when wanting to average something many times per second or just check up on something more often than the usually stepped or heartbeat, etc… allow.

Note:

  • this also works for the client, you just need to change the location of the scripts and stuff in workspace and the scripts to be local scripts.

  • This could impact FPS or tick rate for servers, I don’t think it will be to big of a impact as long as Roblox’s task schedulers recognizes that this thread is basically useless for anything else :laughing:

  • This cannot be used for exact timings as it doesn’t run at the start of each frame so could be off by a little

resource:
image

Updater script:

local runService = game:GetService("RunService")
local actor = script:GetActor()

local updateEvent = script:WaitForChild("Update")

local targetUpdatesPerStep = 1/8 --change this to your desired update rate, currently 1/8 * 1/60 = 480 updates per second (I am assuming 1/60 because of the deltaTime within Stepped)
local minimumUpdateRate = 1/60 -- slowest updating speed

runService.Stepped:ConnectParallel(function(deltaTime)
	debug.profilebegin("Updater")
	
	local frameStartTime = tick()
	local count = 0
	
	--assuming delta time will be same from last frame
	local clampedDeltaTime = math.clamp(deltaTime, 0, minimumUpdateRate)
	
	while true do
		if tick() >= frameStartTime + (clampedDeltaTime)*(count * targetUpdatesPerStep) then
			debug.profilebegin("Update Count: "..tostring(count))
			updateEvent:Fire()
			debug.profileend("Update Count: "..tostring(count))
			
			count += 1
			
			if count == (1/targetUpdatesPerStep) then
				break
			end
		end
	end
	
	debug.profileend("Updater")
end)

CountDisplayer (this isn’t required, instead can be used to validate update rate):

local updateEvent = game:GetService("ServerScriptService"):WaitForChild("Actor"):WaitForChild("Updater"):WaitForChild("Update")

local updatingCount = 0

updateEvent.Event:Connect(function()
	updatingCount += 1
end)

local previousTick = tick()

game:GetService("RunService").Stepped:Connect(function(deltaTime)
	local UpdatesPerStep = updatingCount 
		
	if tick() >= previousTick + 1 then --displaying once a second
		print(UpdatesPerStep)
		
		previousTick = tick()
	end
	
	updatingCount = 0
end)
3 Likes

This has been made in the past, and is not a very good idea. Heres a reply from a similar resource, and I suggest reading through some of the other replies too.

5 Likes