Hi there! This is my first tutorial so please bear with me.
Thanks to @SoCalifornian, @Mystifine and @Avallachi.
In this tutorial, I will be showing you how to make a simple FPS tracker, if you’re already familiar with how to do this then I suggest moving on as this is a fairly simple thing to do.
The first thing you’ll want to do is create a ScreenGui (I assume you’re already in a place)
Once again, you should name it something like “Main” or something like that, and change the properties around to make yours unique
Next is the fun part, scripting it!
What you do first is create a local script, name it “GetFPS” or something like that, and type the code below out, I have added comments to help you out local RunService = game:GetService("RunService")
We’re getting the RunService so we can update the gui each frame
RunService.RenderStepped:Connect(function(frame) -- This will fire every time a frame is rendered
script.Parent.Text = (math.round(1/frame).. " fps")
end)
You can copy and paste this if you want but I suggest actually typing it out.
It’s that simple! Here’s an example video to show it working
You could also calculate the FPS using the DeltaTime argument given by RenderStepped, the change would simply be:
RunService.RenderStepped:Connect(function(deltaTime) -- This will run every time a frame is rendered
main.Text = (math.round(1 / deltaTime) .. " FPS") -- Setting the text of the gui to the FPS and appending "FPS"
end)
This eliminates the function call (plus the second call) and is tied to the actual rendered FPS rather than tied to the Physics FPS
Explanation for beginners:
DeltaTime is simply the time between each frame. We are dividing 1 by DeltaTime because it’ll tell us how many times that number can go into one - basically how many frames we can fit in a second.
So if we are running at 60 FPS, DeltaTime will be 1/60 (1 second per 60 Frames); but, this number will be extremely small (0.0167 in fact)! So to get the actual frame count per second we simply divide 1 by that number!
Thanks for the suggestion! I didn’t do that simply for the reason of this being a basic beginner tutorial and I didn’t want things to get very “mathy” and physics FPS is a good start for beginners