I made a Code to know the Framerate of a Player

I want know if my Code to know the framerate of a player work correctly, here is my code (its a localscript inside the PlayerGui (StarterGui)):

local TextLabel = script.Parent.ScreenGui.TextLabel
local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function(step)
    local fps = 1/step
    if fps < 60 then
        print(fps)
        TextLabel.Text = tostring(fps)
    end
end)

What can I do to improve my code.

5 Likes

Why only print if less than 60?

What’s the purpose of only printing less than 60fps?

2 Likes

Lol that’s not what I meant. If they want us to review the code we should know the purpose of it. I was asking what the purpose of only printing when less than 60 is, to determine if it’s necessary. I’ll edit my original reply.

If anyone manages to run their client faster by modifying it, you won’t know their fps.

2 Likes

This is probably the best you can do right now, I can’t think of another way but to Bind to RenderStep Service and add a Setting to toggle it On and Off for players.

You don’t have to use tostring there, it’s automatic

2 Likes

Why not use GetRealPhysicsFPS?

That way you don’t have to execute this on every frame. Here’s an example based off your current code:

local TextLabel = script.Parent.ScreenGui.TextLabel

while wait(1) do
    local fps = workspace:GetRealPhysicsFPS()
    if fps < 60 then
        print(fps)
        TextLabel.Text = tostring(fps)
    end
end

Physics FPS is different to render FPS.

4 Likes

Sorry, i forgot to write that i inspired me of the Arsenal FPS Calculate system. I dont have see any number over 60.
And here was other reason:

Ok, FPS (Frames Per Seconds), to get the FPS i need to execute this on every frame. The render FPS is the elapsed time between 2 Frames, if i forgot or dont add a frame the calculus will be false.

@RuizuKun_Dev, ahh sorry and thank for have say it to me.

This question has actually been answered before if you do a quick Google search:

3 Likes