I have been sending a tick value from the server to the client then on the client I subtract the received value from the current tick. Most of the time this works but there have been a few instances where I get a negative number from the subtraction. Can someone tell me how this is possible? Is it a Roblox issue or something?
Maybe because tick() is relative to the timezone. I would explore other options like os.time() (UTC, one second precision), DateTime, workspace:GetServerTimeNow() (server time, decent microsecond precision) etc.
workspace:Getservertimenow seems like it will be the best option then since I want the highest accuracy possible to get the players ping. Can’t test it now but I will get back to you once I have.
Are you in studio?
If you are, the ping between you and yourself is… zero. If you are just trying to get the players ping, you could also try to use Player:GetNetworkPing instead?
try using workspace.ReplicatedTime?
I have been using the Studio Settings → Network → the setting that lets you set ping in order to do test on different ping. Also in studio it says the ping is 40, not 0 but even if it was at 0 I don’t see why a negative number would come out as a result.
How accurate is that? Because I need it for projectile prediction?
It’s a fine option. Just worth noting that GetNetworkPing()
should always be a bit less compared to timing a remote function to the server and back because it’s isolated latency and it doesn’t count data deserialization and processing, which is what that 30-40 ms ping should represent. The actual replication should be 0 ms (or whatever you set it in the settings).
And if you send a lot of remotes at once the queuing might further slightly increase the number.
Edit. Also, to avoid any doubt, both GetNetworkPing() and a remote function approximate round trip time (how much time it takes for the packet to travel to the other side and back).
I believe it returns in seconds, but goes into decimals (0.0123456789), so you could just times it by 1000 for milliseconds.
I will do some tests later then get back to this post, thanks for the help everyone!
workspace:GetServerTimeNow() has turned out to be very effective compared to tick from server to client!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.