Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to show users their FPS via textLabel?

Asked by 8 years ago

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:

01local textLabel = Instance.new("TextLabel")
02textLabel.Parent = screenGui
03textLabel.Position = UDim2.new(0, 1450, 0, 700)
04textLabel.Size = UDim2.new(0, 100, 0, 80)
05textLabel.BackgroundColor3 = BrickColor.Black().Color
06textLabel.Text = "0"
07textLabel.Font = "Legacy"
08textLabel.FontSize = 9
09textLabel.TextColor3 = BrickColor.White().Color
10textLabel.BorderColor3 = BrickColor.White().Color
11 
12NewInformation = "XYZ"
13 
14if game.Workspace.FPS == "XYZ" then
15    textLabel.Text = "XYZ"
16end

and

01local textLabel = Instance.new("TextLabel")
02textLabel.Parent = screenGui
03textLabel.Position = UDim2.new(0, 1450, 0, 700)
04textLabel.Size = UDim2.new(0, 100, 0, 80)
05textLabel.BackgroundColor3 = BrickColor.Black().Color
06textLabel.Text = "0"
07textLabel.Font = "Legacy"
08textLabel.FontSize = 9
09textLabel.TextColor3 = BrickColor.White().Color
10textLabel.BorderColor3 = BrickColor.White().Color
11 
12if game.Workspace.FPS == "59.9" or "60" then
13textLabel.Text = "60"
14 
15end

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

Log in to vote
1
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago
Edited 8 years ago

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:

1textLabel.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.

0
How do I get a Clientside Script and where do I put it? :/ spiderman90438 17 — 8y
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. Link150 1355 — 8y
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. Link150 1355 — 8y
Ad
Log in to vote
-3
Answered by 8 years ago

in a localscript

1local fps = workspace:GetRealFPSPhysics()
2local text = tostring(fps)
3print(text)
0
Its not working :/ spiderman90438 17 — 8y
0
It's workspace:GetRealPhysicsFPS(); Im_Kritz 334 — 8y

Answer this question