Using :GetNetworkPing() to get players ping

When GetNetworkPing was introduced to the Roblox API it stated that it would “Provide information in milliseconds”, it also stated it could “Only be accessed on the server”:

Information

Player:GetNetworkPing()
Returns: The users ping (in seconds) <number>

The ping appears to be a One-Way trip as the number it’s returning appears to be half the amount shown on the client Shift+F3 menu.


To rectify this you could always multiply it by 2 which would show you the exact client number (as long as you converted it to milliseconds too by multiply by 1000)

Usages

The new ping function may just seem as a method to return a simple number but it can allow you to help laggy players, such as by compensating on the server such as in FPS Shooter games.

This function could also just be used as a way to show players an accurate method of their ping (However, I am unsure if it works on the client as I have only tested in the studio command bar and on the server F9 Console)

Thanks to @zw1ce for helping me test it out <3

55 Likes

This is really useful as we won’t have to create our own method which in reality created even more ping!

Thanks for sharing I didn’t even know it got added

5 Likes

It was actually a complete coincidence that I discovered it. I just ran :GetNetworkPing() in the command bar in studio and noticed it returned a value.

I hope in the future I can release a tutorial detailing how to use it in lag compensation

Or, you could just do Player:GetNetworkPing() * 2000 instead of Player:GetNetworkPing() * 1000 * 2.

17 Likes

Awesome, this is going to be incredibly useful for developers who work on games that require you to have a good network ping.

The most important thing is that laggy players in shooter games won’t have an unfair advantage :smiley:

Interesting, don’t know why Roblox can’t just have it as a property instead of you needing to call the function. I wonder if it would have performance implications for being called constantly (In my games I have a top bar panel for me that has the FPS and Ping so I can investigate if the game is laggy or not in general & I try to keep it as up-to-date as possible)

Possibly the reason it isn’t a property is because if it was a property the server would need to constantly update it which would be very useless if it wasn’t being used. Where a function can be called when and where it needs to be used which wouldn’t waste any performance as it’s being used.

(just a speculation)

3 Likes

Noticed that the Devhub has actually got updated information but it doesn’t show up when you google it

https://developer.roblox.com/en-us/api-reference/function/Player/GetNetworkPing

4 Likes

Roblox already has tons of these. The property doesn’t have to “update” when you’re not reading from it / it has no Changed listeners. No biggie.

Wouldn’t make sense to have a property.
People would expect it to constantly update and see that update in real-time.


And what sense does it make to have a property that’s only job is to update when you read from it??

Just make it a function. There could also be internal things needed to be called when you call that function.


Oh wait, lemme just assign a variable to Instance.Children to get the children for that instance.

It does if you observe it. Roblox has to keep track of it anyway.

Some properties already exist that work like this. Mouse.Target for example. Simply reading the property causes Roblox to perform the raycast if it hasn’t already. Either that or having the Mouse instance, but it’s basically the same thing.

Still makes no sense for ping as I said:

Therefore Roblox would have to constantly update it as Quantix said:

It’s better off you call a function and get a return for the current ping ONCE rather than it constantly updating itself as a property.

If you want it constantly, place it in a while loop or a RunService function.


As I said as a reference to this:

You have :GetChildren(), why not place that as a property???
Why is :GetNetworkPing() any different?

They both return what you’re requesting, that’s literally all.

2 Likes

I state exactly that
I also state how to solve that too

1 Like

I LITERALLY say that in the post

(as long as you converted it to milliseconds too by multiply by 1000)

2 Likes

I tested it myself in those screenshots and the numbers provided appear to be correct, if you have an alternate theory I would love to see some evidence or some screenshots provided but right now I don’t believe there is anything else.

I have noticed some gaps between the ping shown on the Shift + F3 menu and the one returned by this function and they seem to not be linked and it may have only been a rare occurance that the ping lined up.

You did however state I was incorrect by saying

which was why I was confused as I had already written that down.

:GetNetworkping multiplied by 1000 seems to be more accurate than than GetNetworkping *1000 *2 , why did you add that in your tutorial?

Yeah, I don’t think that gap is correct:

The current ping was 178ms, and if I calculate the last number that was logged to the output:

0.054000001400709 * 1000

Answer:

If I multiply it by 2, that would be the closest result to my actual ping

There shouldn’t be a gap that large at all. If there is that means it’s returning inaccurate ping.


I tested this several times and got the same thing (in-game).
Someone else I knew even tested this and also got results not matching their current ping.


With my results, there no way it could be some fixed interval.

Also, GetNetworkping is not complete so don’t expect it to be perfect , so just wait and Les see if it gets any more accurate/better

I’ll have to look into that. Thanks for the info. You’re very helpful

A way i found to get the ping delay is by having a NumberValue in workspace that i set on server with time(), then i compare it on client side by substracting client time() from it. I dono how accurate is this but it seems to work in studio too when i adjust the StudioSettings/Network/IncomingReplicationLag