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

Any way to get the client's ping?

Asked by 4 years ago
Edited 4 years ago

Hello scripters! This is my first question soo yeah. My question is.. Is there a way to get the client's ping? I have seen this in games like Arsenal. I tried using this code:

1local currentPing = tick() -- epoch time
2while wait(1) do
3    currentPing = (currentPing()-tick())
4    print(currentPing)
5end

but sadly it doesn't work. I even tried using ping meters. Most of them are giving me errors. Any help? Also, I want to make a GUI that can show the player their ping.]

Edit: I used this code:

1while wait() do
2    local ping = (1/wait())
3    print("Your ping is "..ping)
4end

and it was fairly better than 0 (no offense).

Please help!

2 answers

Log in to vote
0
Answered by 4 years ago

Considering ping is usually round trip time (Client ? Server ? Client), a RemoteFunction would be a good way to measure it. Simply compare the time you invoke the server and the time when it gets back. Something like this:

Client

1local function getPing()
2    local start = tick()
3    RemoteFunction:InvokeServer()
4    return tick() - start
5end

Server

1RemoteFunction.OnServerInvoke = function(player)
2    return
3end
0
nope. it does not work. i printed the ping and it printed stuff around 0.9 when my ping is much much more than...0.9. DragonSpawner12 61 — 4y
0
That's your ping in seconds. Usually ping is measured in milliseconds, so simply multiply that result you get by 1000 and you'll get a ping you're used to. Sometimes ping is also measured in half of the round trip instead of the full round trip, so in that case you could multiply it by 500 instead. cowsoncows 951 — 4y
0
i accept this answer but can you get the ***exact*** amount? in the output, the ping is around 50. but my actual ping is like 30, 60, 90, 80, 10 etc. DragonSpawner12 61 — 4y
0
by any chance can you test this out yourself? im using the performance stats to check the actual ping.. DragonSpawner12 61 — 4y
Ad
Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You could use a Remote event, and check how long it takes for it to go to the server.

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

Local script:

1local RemoteEvent =  -- remote event
2local player = game.Players.LocalPlayer
3while wait(1) do
4    local Tick = tick()
5    RemoteEvent:FireServer(player, Tick)
6end

Server:

1local RemoteEvent = -- remote event
2RemoteEvent.OnServerEvent:Connect(
3    function(Tick)
4        local ping = ((tick() - Tick) - 1)
5        print(player.Name .. " ping is " .. ping .. ".")
6    end
7)

Answer this question