Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to show users their FPS via textLabel?

I have a textLabel that I am gonna use to show people their FPS - Frames Per Second in the game, I want it so whatever the string of FPS is the string of textLabel is too, I don't know how to do this but wrote attempt codes here:

local textLabel = Instance.new("TextLabel")
textLabel.Parent = screenGui
textLabel.Position = UDim2.new(0, 1450, 0, 700)
textLabel.Size = UDim2.new(0, 100, 0, 80)
textLabel.BackgroundColor3 = BrickColor.Black().Color
textLabel.Text = "0"
textLabel.Font = "Legacy"
textLabel.FontSize = 9
textLabel.TextColor3 = BrickColor.White().Color
textLabel.BorderColor3 = BrickColor.White().Color

NewInformation = "XYZ"

if game.Workspace.FPS == "XYZ" then
	textLabel.Text = "XYZ"
end

and

local textLabel = Instance.new("TextLabel")
textLabel.Parent = screenGui
textLabel.Position = UDim2.new(0, 1450, 0, 700)
textLabel.Size = UDim2.new(0, 100, 0, 80)
textLabel.BackgroundColor3 = BrickColor.Black().Color
textLabel.Text = "0"
textLabel.Font = "Legacy"
textLabel.FontSize = 9
textLabel.TextColor3 = BrickColor.White().Color
textLabel.BorderColor3 = BrickColor.White().Color

if game.Workspace.FPS == "59.9" or "60" then
textLabel.Text = "60"

end

But the problem is I don't think that is how you locate the game's FPS and I don't think that is how you put the string on the textLabel, I honestly have no idea can you guys help me?

2 answers

✓ Accepted answer

You are correct about setting the Text property of a TextLabel object. Now then, you can get a client's framerate through the GetRealPhysicsFPS method of Workspace:

textLabel.Text = game.Workspace:GetRealPhysicsFPS()

Of course, since the framerate is different from player to player, you will have to do this from a clientside script.

Note that GetRealPhysicsFPS's return value is a number, while a TextLabel's Text property is of type string. This isn't a problem for us, as numbers in Lua are automatically converted to string when necessary.


Conclusion

So, there you have it. Easy, right?

If this helped then please be sure to accept, and optionally upvote, my answer. It helps both of us. ;) If you need anything else, you need only ask.

3 comments

0

How do I get a Clientside Script and where do I put it? :/

1

What we often call a "clientside script" is a LocalScript object. LocalScripts are executed on the client, that is, a player's computer. Hence their name. Similarly, we also call regular Scripts "serverside script", because they are executed on the server itself; the computer at the Roblox HQ that hosts the game.

0

As for where to put it, it depends really. But I would suggest putting it in a pre-existing gui, located in StarterGui, instead of creating the gui (including the TextLabel) at runtime.

in a localscript

local fps = workspace:GetRealFPSPhysics()
local text = tostring(fps)
print(text)

2 comments

0

Its not working :/

0

It's workspace:GetRealPhysicsFPS();

This discussion is preserved as it was. New answers, comments, and votes are closed.