1 | |
2 | local UpdateInterval = 1 |
3 | |
4 | local gui = Instance.new("ScreenGui") |
5 | gui.Name = "FPSCounter" |
6 | gui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui") |
7 | |
8 | local fpsLabel = Instance.new("TextLabel") |
9 | fpsLabel.Name = "FPSLabel" |
10 | fpsLabel.Size = UDim2.new(0, 100, 0, 20) |
11 | fpsLabel.Position = UDim2.new(1, -110, 0, 10) |
12 | fpsLabel.BackgroundColor3 = Color3.fromRGB(0, 0, 0) |
13 | fpsLabel.TextColor3 = Color3.fromRGB(255, 255, 255) |
14 | fpsLabel.TextStrokeColor3 = Color3.fromRGB(0, 0, 0) |
15 | fpsLabel.TextStrokeTransparency = 0 |
16 | fpsLabel.Font = Enum.Font.SourceSans |
17 | fpsLabel.TextSize = 18 |
18 | fpsLabel.Text = "FPS: --" |
19 | fpsLabel.Parent = gui |
20 | |
21 | |
22 | local frameCount = 0 |
23 | local lastUpdateTime = os.clock() |
24 | |
25 | |
26 | local function updateFPSCounter() |
27 | frameCount = frameCount + 1 |
28 | local currentTime = os.clock() |
29 | |
30 | |
31 | local elapsedTime = currentTime - lastUpdateTime |
32 | |
33 | |
34 | if elapsedTime >= UpdateInterval then |
35 | local fps = frameCount / elapsedTime |
36 | fpsLabel.Text = string.format("FPS: %.2f", fps) |
37 | |
38 | |
39 | frameCount = 0 |
40 | lastUpdateTime = currentTime |
41 | end |
42 | end |
43 | |
44 | |
45 | game:GetService("RunService").RenderStepped:Connect(updateFPSCounter) |