Making a Ping meter

Hi, I got an idea to make a ping meter for my game. To display it to the player and warn if there is a chance of getting disconnected.

I had no idea how to do this because the network things are unknown to me.

I don’t need the full code for it, can you just push me in the right direction?

Thanks.

I’m not sure your application makes sense, but if you want to have the client ping the server periodically, you can just have a RemoteFunction in ReplicatedStorage:

Server side:

function remoteFunction.OnServerInvoke(player)
    return true
end

Client side:

local function Ping()
    local start = os.clock() -- or tick() or whatever
    remoteFunction:InvokeServer()
    return os.clock() - start
end

print("Ping: " .. Ping() .. " seconds")

The server pinging clients is harder, because you shouldn’t use RemoteFunctions for that. You can use two RemoteEvents instead.

4 Likes

This is how I would do it:

To make a ping metter I would make a type of communication between server and client (which is what ping does) and use tick() for that.

So basically, you will need to use tick() 2 times, in the server and then in the client and using a remote event for this.

So it would look like:

runService.Heartbeat:Connect(function()
       remoteEvent:FireAllClients(tick())
end)

(I forgot if Heartbeat or Stepped cant be used in server so yeah)

remoteEvent.OnClientEvent:Connect(function(theTick)
       print(tick() - theTick) -- It will print a really small number.
end)
1 Like