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:

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

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:

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.

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

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

Answer this question