Hello! I’m working on weapons for a game and some of those weapons are projectile-based, with some extrapolation functionalities to help make the experience smoother for players. However I’ve noticed that a player may choose to voluntarily turn their wi-fi connection off for a short while (or they may simply have a lag spike), and in that scenario, I would like to only let their projectile move forward for a short amount of time (if this lag spike is too long, I would like to eventually freeze their projectiles and only resume when they start receiving data from the server again).
Is there a way to achieve this? Any value I could read, function I could run, to quickly notice when the server stops sending me any information?
Basically, my question is how I would fill the blanks of this script:
function isPlayerLagSpiking()
--TODO detect if the player is not receiving any info from the server (use variables outside of the function's scope if needed)
end
counter = 0
threshold = 0.5
game:GetService("RunService").Stepped:Connect(function(t, dt)
if not isPlayerLagSpiking() then
if counter > threshold then
warn("Lagspike is over.")
end
counter = 0
return
end
counter += dt
if counter > threshold and counter - dt <= threshold then
warn("Player is having a lag spike!")
end
end