My current setup is basically having a firerate value and checking if the time that has elapsed since the last shot is greater than the firerate (the cooldown basically). Same goes for automatic guns but I utilized other variables here to account for the framerate changes.
function startFiring()
-- also accounts for the ammo
local coolDown = 60 / Config.Firerate
if Config.Auto then
-- FireServer when firing begins
local timeElapsed = 0
local frameDelta = 0
repeat
timeElapsed = timeElapsed + frameDelta
if timeElapsed >= coolDown then
timeElapsed = timeElapsed - coolDown
end
frameDelta = RunService.Heartbeat:Wait()
until firing == false
-- FireServer when firing ends
else -- if not automatic
local timeElapsed = os.clock() - fireDebounce
if timeElapsed >= coolDown then
FireRequest:FireServer(firearm) -- does the sanity check and enables a canFire player debounce
fireDebounce = os.clock()
end
end
end
The issue is I’m planning on doing a sanity check for when the gun has been fired to see if the player is not getting the gun spammed way above the firerate. How will I check for the time elapsed on the server side as well so I can compare it to that of the client? Should I also do the same thing as I did on the client (same setup) but on the serverside? Anything I’m doing that is wrong? First time working with sanity checks of this scale.