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!
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
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 )