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

How would I make a gui that shows ping and fps?

I'm wondering how I would even start to make a gui/menu to show fps or ping? What would I have to get to show the client's fps?

1 answer

✓ Accepted answer

Making a GUI display FPS is relatively easy:

--Insert inside your TextLabel

local Heartbeat = game:GetService("RunService").Heartbeat
local tick = tick

local LastIteration, Start
local FrameUpdateTable = {}

local function HeartbeatUpdate()
	LastIteration = tick()
	for Index = #FrameUpdateTable, 1, -1 do
		FrameUpdateTable[Index + 1] = (FrameUpdateTable[Index] >= LastIteration - 1) and FrameUpdateTable[Index] or nil
	end
	FrameUpdateTable[1] = LastIteration
	local Current = (tick() - Start >= 1 and #FrameUpdateTable) or (#FrameUpdateTable / (tick() - Start))
	Current = Current - Current % 1
	script.Parent.Text = "FPS: "..Current
end
	
Start = tick()
Heartbeat:Connect(HeartbeatUpdate)

However since Ping is the latency between the server and the client, you'll need to use a Remote Function on ReplicatedStorage and use a Server-Side script in ServerScriptService in order to interact with both the Client and the Server, so we'll use 2 scripts:

1.-

--TextLabel (LocalScript)

local ServerReturn = game.ReplicatedStorage:WaitForChild("RemoteFunction")

function GetLatency()
	local t = tick()
	ServerReturn:InvokeServer("ping")
	local latency = tick()-t
	return math.floor((latency / 2) * 1000)
end

while wait(1) do --add a wait so it doesn't crash the game
	script.Parent.Text = "Ping: "..GetLatency().."ms"
end

2.-

--ServerScriptService (Script)

game.ReplicatedStorage:WaitForChild("RemoteFunction").OnServerInvoke = function(player, oof) -- "oof" can be named however you want I think
	if oof == "ping" then
		return "received"
	end	
end

Hope it helps.

1 comment

0

I can understand how the ping and the fps would work. Thank you for explaining how to make a fps script and a script to show ping. - Zeta

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