For some unusual reason, even when i put a ShotDelay to prevent fast firerates on high FPS, it doesn’t work…
Here’s a video on 120FPS
Here’s a video on 30FPS
Here’s the Gun Local Script:
RunService.RenderStepped:Connect(function(dt)
if Auto ~= true then return end
if HeldDown == true then
if CanFire and Ammo > 0 then
Ammo -= 1
CanFire = false
MainModule.Shoot(Mouse, FirePos, FireCF, Attachment, RecoilSpring, Up, Sideways, Shake, Gun, dt)
LoadAmmo()
task.wait(ShotDelay) --!!! Quite Literally a ShotDelay to prevent fast firerates, but it doesnt work
CanFire = true
elseif CanFire and Ammo <= 0 and Reloading == false then
Reloading = true
Ammo = MainModule.Reload(Viewmodel, Viewmodel.Reload, OrgAmmo, Gun)
LoadAmmo()
Reloading = false
end
end
end)
There may be some sort of asynchronous operation happening in your obscure functions (MainModule.Shoot and LoadAmmo) which is delaying the current thread, which could result in lower firerate for people with lower fps, since it would take them longer to get to the task.wait() to begin. Honestly no way to know for sure since too much of underlying code is obscured. Either way, a more robust way to do this rather than suspending the thread would be to log the time of the last shot and then find the current different in time of the last shot to see if it is at or exceeds the intended “ShotDelay”.
An example might look like this:
local lastShot = os.clock() -- initialize it for ease of use and relevant scope
RunService.RenderStepped:Connect(function(dt)
if Auto ~= true then return end
if HeldDown == true then
local CanFire = os.clock() - lastShot >= ShotDelay
if CanFire and Ammo > 0 then
lastShot = os.clock()
Ammo -= 1
MainModule.Shoot(Mouse, FirePos, FireCF, Attachment, RecoilSpring, Up, Sideways, Shake, Gun, dt)
LoadAmmo()
elseif CanFire and Ammo <= 0 and Reloading == false then
Reloading = true
Ammo = MainModule.Reload(Viewmodel, Viewmodel.Reload, OrgAmmo, Gun)
LoadAmmo()
Reloading = false
end
end
end)