Hey Developers, I’ve basically been trying to figure out a way of detecting whether or not a person is 100% lagging I can’t really seem to come up with a stable algorithm. Do any of you happen to know of some type of algorithm that can help with what I’m trying to do? The algorithm I’ve came up with it works just it’s not entirely accurate and I had to use messy methods for it.
I am not sure what way you’d like a “Lag Detection” system but I came up with this, hopefully it works.
local MAX_PING = 500 -- milliseconds
local MIN_FRAME_RATE = 30 -- frames per second
local lastTick = tick()
local frameCount = 0
game:GetService("RunService").RenderStepped:Connect(function()
local now = tick()
if now - lastTick >= 1 then
local frameRate = frameCount / (now - lastTick)
if frameRate < MIN_FRAME_RATE then
print("Lag detected: low frame rate ("..frameRate.." fps)")
end
lastTick = now
frameCount = 0
else
frameCount = frameCount + 1
end
end)
this script works good enough, but I would use os.clock for its increased precision
If it works it works, I wrapped up a script to see if this is what pacify wanted.
If you’re referring to network lag (which is when the player stops moving on the server), you can obtain that through a server script using Player:GetNetworkPing()
if I’m not mistaken.
If you’re talking about low framerates (when the player moves slowly or you get low FPS), use the above solution.
Hi, pretty much what I’m trying to do is to validate that a player is actually lagging on the server.
In that case, you would use Player:GetNetworkPing()
. You’d have a loop and detect if this ping is over a certain number. Then, you can tell if the player is lagging.
Does this work on the server? Or is this specifically for client.
It can work on both. The only issue is that a client cannot get the ping of another client because Roblox does not use peer-to-peer networking.
Ah, is it 0 by default in roblox studio?
Yes, I’d assume so. You can try to test this with IncomingReplicationLag
in studio settings, but I’m not sure if that will change the simulated ping.