If you play First-Person-Shooting games enough like Arsenal, Phantom Forces and others, you would probably see these 2 words a lot. FPS and ping/latency. I’m curious of how they actually work in the game. The problem is, I had no idea on how does these 2 things work. If anyone could explain or share me some ideas on how does it work, it’s much appreciated. Please don’t give me full scripts of it as I might not understand it well.
FPS is frames per second. Remember, a video is a bunch of moving pictures, and so is a video game.
Ping is how fast (i believe in milliseconds) that the computer communicates with the server. A low number is best.
Latency is when your FPS and ping are bad, so things are slow.
You can’t script them in Roblox; they just happen.
Then how is it possible that Arsenal managed to make it?
Wait a minute, you mean FPS first person shooter
They did make a first person shooter, but they didn’t make ping!
edit: If I’m wrong please tell me. If you mean frames-per-second, I can assure you that Arsenal did not make it @ItzMeZeus_IGotHacked
I mean, is there a script that shows you frames per seconds and ping? If not, why did Arsenal managed to have it in their game?
I know that you can probably use
RunService.Heartbeat
for the FPS showing. For ping, I imagine a LocalScript and ServerScript communicate, and your ping is the math.floor()
ed result of the difference of tick()
s.
Can I like have a script example of this? Is there a math equation behind this?
What does math.floor() do in this!m?
There’s a diagram showing each RunService
event in another topic about it:
FPS can be calculated using these events, but I’m not quite accurate how the function should be written exactly. The best guess is to check how many times the events can fire in a second. Ping is different and is measured in ms
, where it sends a signal back and forth.
FPS (commenting a lot so it’s not spoonfeeding):
-- Note I have not tested this, but I will in a second
local num = 1
repeat
game:GetService("RunService").Heartbeat:Wait() -- waits for 1 frame
num += game:GetService("RunService").Heartbeat:Wait() -- adds to the number
until math.floor(num) >= 2 -- repeats for one second
Note I have never done a script like that so likely broken.
Ping:
Local:
local tick = tick()
game:GetService("ReplicatedStorage").RemoteEvent:FireServer(tick) -- tells the server your first tick
Server:
game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent:Connect(function(p, tick1)
local tick2 = tick()
print("The ping of " .. p.Name .. " is " .. math.floor(tick2 - tick1))
end)
I’m not quite sure, but maybe the combination of RunService.Heartbeat:Connect()
and coroutines
should work perfectly. The coroutines would add a value to the FPS meter and then have to yield a second before discarding its value from the meter.
I believe that to get ping you don’t only remoteevent to the server, but rather remotefunction with return of tick (best to use is os.clock()
, it’s faster)
FPS are actually hard to calculate, and they’re not always accurate in Roblox.
These values are somewhat estimated i guess.
The fastest method to calculate fps might be this:
local rs = game:GetService'RunService';
local fps = 0;
rs.RenderStepped:Connect(function(step)
fps = 1 / step;
end;
However as I stated, it’s not neccessarily accurate.
I’ve seen some scripts that people made, which calculate fps more precisely, but you would need to search for them for yourself cause i forgot where did i find them.
Somewhere on devforum I think.
As of for ping:
-- CLIENT:
local rs = game:GetService'RunService';
local rf = game.ReplicatedStorage.remotefunction;
rs.RenderStepped:Connect(function()
local ping = rf:InvokeServer(os.clock());
end);
-- SERVER:
local rf = game.ReplicatedStorage.remotefunction;
rf.OnServerInvoke = function(plr,t)
return os.clock() - t;
end;
As you can see, ping is how many miliseconds does it take to communicate with server.
Lower = better.
I think that Roblox should offer developers built-in functions for getting FPS and/or ping, which would be more precise than this what we can do. But that’s only my opinion.
Have a nice day!
If you don’t know what ping is, I wrote a somewhat detailed reply to another topic about it, which you can read more about here: Less ping in Roblox Studio than in RobloxPlayerBeta! - #13 by Affenity
Ping is basically about how fast something is replicated (changes / creations / deletions update, if you want). The lower ping, the better. Ping of 10 means it takes 10 milliseconds to update something, while a ping of 1000 will take 1000 milliseconds to update (an entire second). Imagine you have 1000 in ping and shoot someone, this will cause a horrible experience because you won’t get the kill before 1 second later, and the player you just killed will be confused as to what happened because for them, they shot you too.
FPS (frames per second) is about how many times the content on your screen is being updated every second. Here, the higher the better, because you will get a smoother experience when playing games. Note that most monitors people have are capped to 60Hz (60 FPS) and you can argue that giving them more than 60FPS wouldn’t be noticeable and would be a waste of resources.
If you’re wondering about how you should go ahead and implement networking in your game, a good reference point would be a video from the developers of Halo: Reach, where they explain various issues they had and discussed design choices when it came to networking. Note that some parts of the video aren’t relevant as they’re focusing on low-level stuff when it comes to networking, which is something you can’t control in Roblox (yet?). Feel free to watch it: https://www.youtube.com/watch?v=h47zZrqjgLc
May i know why your using 1 as the number?
Since we want to get the number of frames per second, we divide 1
by step
.
step
is a double, which determines how many seconds have passed since the last frame.
More here.
Have a nice day!
What does t stands for? Is it the player?
From what I understand, ping is the amount of time that the server and client takes to communicate with each other. A higher ping means that the game will take longer to communicate with the server and appear to be frozen or laggy. A lower ping is better, in my country, ping nears around 100ms but I’ve seen that in the US it’s about 50ms.
Oh sorry, I made a silly mistake…
The first parameter of OnServerInvoke
function should always be player. I am correcting that now!
t
is meant to be os.clock()
, which:
“Returns the amount of CPU time used by Lua in seconds. This value has high precision, about 1 microsecond, and is intended for use in benchmarking.”
So, knowing this, we can subtract os.clock()
from t
to get the elapsed time in ms (In this scenario: between firing the remote and receiving it)
Have a nice day!