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:

local currentPing = tick() -- epoch time
while wait(1) do
    currentPing = (currentPing()-tick())
    print(currentPing)
end

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:

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

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

local function getPing()
    local start = tick()
    RemoteFunction:InvokeServer()
    return tick() - start
end

Server

RemoteFunction.OnServerInvoke = function(player)
    return
end
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:

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

Server:

local RemoteEvent = -- remote event
RemoteEvent.OnServerEvent:Connect(
    function(Tick)
        local ping = ((tick() - Tick) - 1)
        print(player.Name .. " ping is " .. ping .. ".")
    end
)

Answer this question