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

Grabbing The Servers Ping?

Asked by
Donut792 216 Moderation Voter
4 years ago

alright so there is probably some extremely simple line of code somewhere that i couldn't find but i am wanting to know if there is a way to grab the ping of the actual server like say perhaps take the value from the dev console and put it on a textgui or it that is not an option then get the average ping from each player and round it up into a value that i can slap on a textgui later which i know getting a localplayers ping is possible but im not sure how to do that either

1 answer

Log in to vote
1
Answered by
crywink 419 Moderation Voter
4 years ago
Edited 4 years ago

If you're trying to get a player's ping, you can simply just invoke a RemoteFunction and since the script will yield until it receives a reply, subtract the time it came back by the time you invoked the function. I'll provide a code example below...

Client:

local RemoteFunction = game.ReplicatedStorage.RemoteFunction

local function GetPing()
    local Start = tick()
    RemoteFunction:InvokeServer() -- Invoke a useless function to yield until given a reply.

    return tick() - Start
end

print(GetPing()) -- Oh, there's our ping! :)

Server:

local RemoteFunction = game.ReplicatedStorage.RemoteFunction

RemoteFunction.OnServerInvoke = function(plr)
    return true
end

Hope this helps! If you need any more information, feel free to ask.

If this helped, please remember to accept the answer.

1
Thank you a lot man! this really didnt even cross my mind Donut792 216 — 4y
Ad

Answer this question