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)
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)
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
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
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
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.
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.