How can I make a Ping Reader GUI?

Hello, I was wondering how I could make a Ping reader GUI? I have already made an FPS reader GUI and I tried turning it into a Ping Reader but it didn’t work here is my FPS reader code.

local fps = 0

local rs = game:GetService("RunService")

rs.RenderStepped:Connect(function()
	fps = fps + 1
end)

while true do
	script.Parent.Text = "FPS: "..fps
	fps = 0
	wait(1)
end

And here was my Attempted Ping Reader GUI (But it still just read your FPS even though it looked like this)

local Ping = 0

local rs = game:GetService("RunService")

rs.RenderStepped:Connect(function()
	Ping = Ping + 1
end)

while true do
	script.Parent.Text = "Ping: "..Ping
	Ping = 0
	wait(1)
end
6 Likes

You can just use the property of workspace in a local script for it.
This would be for fps.

 while wait(1) do
    local fps = game.Workspace:GetRealPhysicsFPS() 
    print(fps)
end

You can read more about it here: GetRealPhysicsFPS

1 Like

1/RenderStepped:Wait() is the correct way to get it iirc

3 Likes

Thanks, it worked! :smiley: (30 characters)

Ping, otherwise called Latency, is how many seconds it takes to send data to another device, such as the server. Getting the player’s ping would need you to use a RemoteFunction that invokes a request to the server and the server will get back to the client:

-- Server

RemoteFunction.OnServerInvoke = function(player)
    return "received"
end)

-- Client

local t = tick()
RemoteFunction:InvokeServer()
local ping = ((tick() - t) / 2) * 1000 -- time it takes in milliseconds

You’d need to do this about once every second to reduce the traffic over the network


@MrMouse2405 Physics FPS is different from Render FPS; That function returns how frequently the physics is updated every second, not how frequently the world is rendered on their screen.

The correct way to get the FPS would be what @Legoracer said

25 Likes

Wait I just realized this is the solution because I was asking for Ping not FPS, so this is the right solution. Also Sorry about that, lol

2 Likes

My bad, I misred as FPS as well due to first example.

Also this is kind of late but I would appreciate if I could show the Ping in Whole numbers, sorry for the late response.

Use math.floor:

local ping = math.floor(((tick() - t) / 2) * 1000)
2 Likes

Thanks so much for your help that also worked! :smiley:

1 Like

image

lol

Please do not bump old topics.

Anyways, looks like they did not math.floor the value.

i’ve noticed the date of the posts after i posted this…my bad

I believe math.floor is broken right now, I have no idea why, but even math.floor ing something will just return a number similar to this:

34.0000001

math.round? _________________________________________

Yes, in some cases it just returns be unrounded number: