Clean Topbar FPS Counter

I made this FPS indicator, works and looks nice so i chose to share it with everyone :slight_smile:

Demonstration video:

File (StarterGui):
Topbat FPS.rbxm (5.3 KB)

Raw code:

--CODED BY V1SIONUSE--

local fps = 0
local rs = game:GetService("RunService")
local textLabel = script.Parent
local tweenService = game:GetService("TweenService")
local textColors = {
	Red = Color3.fromRGB(255, 0, 0),
	White = Color3.fromRGB(255, 255, 255)
}

function updateFPS()
	fps = fps + 1
end

rs.RenderStepped:Connect(updateFPS)

local function blinkText()
	local originalColor = textLabel.TextColor3
	local blinkColor = textColors.Red
	local tweenDuration = 0.2  -- Duration of each blink in seconds
	local numBlinks = 6  -- Number of times to blink

	for i = 1, numBlinks do
		local blinkTween = tweenService:Create(textLabel, TweenInfo.new(tweenDuration), { TextColor3 = blinkColor })
		blinkTween:Play()
		blinkTween.Completed:Wait()
		local originalTween = tweenService:Create(textLabel, TweenInfo.new(tweenDuration), { TextColor3 = originalColor })
		originalTween:Play()
		originalTween.Completed:Wait()
	end

	textLabel.TextColor3 = originalColor
end

while wait(1) do
	textLabel.Text = fps .. " FPS"
	local targetColor
	if fps < 30 then
		targetColor = textColors.Red
		blinkText()
	else
		targetColor = textColors.White
	end
	local currentColor = textLabel.TextColor3
	local tweenInfo = TweenInfo.new(0.5)  -- Set the duration of the tween in seconds
	local tween = tweenService:Create(textLabel, tweenInfo, { TextColor3 = targetColor })
	tween:Play()
	fps = 0
end
13 Likes

Cool Resource, but I recommend using TopbarPlus and NumberSpinner, as they do a better job on that, Here is the code which can help you (no copy paste!)

local RunService = game:GetService("RunService")

local Icon = require(game.ReplicatedStorage.Icon)
local NumberSpinner = require(game.ReplicatedStorage.NumberSpinner)

local fps = 0

RunService.RenderStepped:Connect(function()
	fps += 1
end)

local icon = Icon.new()
icon:setRight()
icon:lock()
icon:setSize(75, 32)
icon:give(function(ic)
	local spinner = NumberSpinner.new()
	ic:convertLabelToNumberSpinner(spinner)
	spinner.Duration = 0.25
	spinner.Prefix = ""
	spinner.Suffix = " FPS"
	spinner.Decimals = 0
	coroutine.wrap(function() 
		while task.wait(1) do
			spinner.Value = fps
			fps = 0
		end
	end)()
end)

This is the model (packed using @LambHubGoBrrrrr’s Packer Plugin) FPSCounter.rbxm, but you don’t need it if you are fine by installing it by hand

5 Likes

Did you know that RunService.RenderStepped(deltaTime) exists

3 Likes

the code already uses it

you would need to check the code again

2 Likes

Hi I said deltaTime can you check if the original code even uses that thank you

3 Likes

ok, then what do you do with the deltaTime also i know there isn’t that in the original code

1 Like

Mind I remind you, the original code is wrapping everything in a while wait(1) do which clearly is a bad practice. We can always use the provided deltaTime which tells us how long it has elapsed since the last RenderStep.

4 Likes

This is completely unrelated to the resource and is just you trying to give out a different resource. This gives no feedback.

3 Likes

I’m just explaining that it’s already achievable using TopbarPlus, NumberSpinner and one script

2 Likes

That’s amazing and I congratulate you, but instead of just posting a random script and calling the OP’s resource reinventing the wheel, I suggest giving a suggestion on how exactly they could improve by using their code with examples.

Also, your code you replied with has unused variables.

3 Likes

I edited the post, and what are the unused variables?

looks cool, but it’s missing the flashing red on low performance

Tweens are created to be reused. Please reuse the tweens instead of creating new ones :pray: Takes a toll on the perfomance even more :sob:

1 Like

Why are you counting the fps every second instead of using 1/deltaTime? It takes longer to read the fps (and task.wait is not accurate).

1 Like