RenderStepped Returning 0

image
For some reason, my FPS counter ocasionally calculates an infinite amount of FPS.
I’m using an FPS unlocker on the ROBLOX client and am frequently achieving more than 1000 fps. While getting the number of fps from the equation, I think that sometimes the time gap between frames is so low that ROBLOX rounds it down to 0, resulting in the script calculating “inf” fps.

Here is my script:

local RunService = game:GetService("RunService")
local db = false
local cd = 0.025
local fps = 0

local floor = math.floor

RunService.RenderStepped:Connect(function(S)
	if db == false then
		db = true
		fps = floor(1/S)
		TextLabel.Text = "FPS: " .. fps
		if fps > 10000 then
			print("Calculated FPS: " .. fps)
			print("Step: " .. S)
			wait(10) -- I added this here so I could take the screenshot at the top of the DevForum post
		end
		task.wait(cd)
		db = false
	end
end)

Does anyone know how to fix this?

1 Like

You floored the FPS variable, that’s why it turned into zero, consider changing fps = floor(1/S) to fps = 1/S

here is a better FPS counter

local RunService = game:GetService("RunService")
local TextLabel = script.Parent

local TimeFunction = RunService:IsRunning() and time or os.clock

local LastIteration, Start
local FrameUpdateTable = {}

local function HeartbeatUpdate()
	LastIteration = TimeFunction()
	for Index = #FrameUpdateTable, 1, -1 do
		FrameUpdateTable[Index + 1] = FrameUpdateTable[Index] >= LastIteration - 1 and FrameUpdateTable[Index] or nil
	end

	FrameUpdateTable[1] = LastIteration
	local FPS = math.floor(TimeFunction() - Start >= 1 and #FrameUpdateTable or #FrameUpdateTable / (TimeFunction() - Start))
	TextLabel.Text =  tostring(FPS).. " FPS"
	if FPS > 200 then
		print("Calculated FPS: " .. FPS)
	end	
end

Start = TimeFunction()
RunService.Heartbeat:Connect(HeartbeatUpdate)
1 Like

math.floor changes it to 0 or a whole number, and workspace:GetRealPhysicsFPS() gets the actual FPS (frames per second) instead of using 1/S, and that is useful for removing exploiters using a FPS Booster, here is some example from the documents Workspace | Roblox Creator Documentation

local RunService = game:GetService("RunService")
local db = false
local cd = 0.025

RunService.RenderStepped:Connect(function(S)
	if db == true then return end

	local fps = workspace:GetRealPhysicsFPS()
 	db = true

TextLabel.Text = "FPS: " .. fps
	if fps > 10000 then
		print("Calculated FPS: " .. fps)
		print("Step: " .. S)
		wait(10) -- I added this here so I could take the screenshot at the top of the DevForum post
	end
	task.wait(cd)
	db = false
end)

first you need to put the GetReakPhysicsFPS() inside the RenderStepped to keep it always updating the FPS counter however he want an FPS counter for the client not for the server so i think GetReakPhysicsFPS() is not gonna help

image

You spelled GetRealPhysicsFPS wrong

thank you for telling me :slight_smile:

bruh it works for the client, the studio-command bar is for client

Even when I printed the Step parameter from RenderStepped, it returned 0 in the console.

Edit: (without flooring the value)

I would much rather program things myself than leech off of others, but thanks for showing me another way

You can test it by your self if you want to

I am only flooring the product of 1 divided by S (Step parameter in RunService.RenderStepped event)
But I tried removing the math.floor and it achieved the exact same result.


It’s not like I’m flooring the Step parameter or something, if I did that then the counter wouldn’t work otherwise. The only problem is that sometimes “Step” is 0

1 Like

Then it’s not really the scripting problem since the problem also involves you using an fps unlocker resulting weird issues and that’s out of my scripting boundaries. Try making your FPS to something lower to check it works just fine

anything divided by 0 always return infinite

(0.042739235478 / 0) -> inf
(0 / 0) -> NaN

also I think you arent even updating the topbar text

1 Like

I am, it’s just I added a wait for when it returns ‘inf’ so I can take a screenshot of it before it flickers away

It works with a lower fps but the fact that it sometimes displays as ‘inf’ when the time between frames is so low that the Roblox client determines it’s 0, it’s so annoying.

1 Like

I’ve tested yours and it performs well, how does it work?
I’d like to know so I can base mine off of it and change how I do the calculations

1 Like

Looks like he’s just manually counting frames instead of using delta time. Another reason this version is advantageous is because by nature it produces a more smooth result, rather than bouncing around every time you get a frame that takes longer than others.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.