I want my weapon to fire multiple times if needed incase it cannot keep up with the firerate of a certain weapon because of fps.
Currently the max firerate is 60 shots per second if the player hasn’t got an fps unlocker and is running roblox at a stable fps. But let’s say I want the firerate to be 120 shots per second which means it should fire twice per second or if the player has 30 fps but the gun fires 60 shots per second it also has to fire twice but I have no idea how to figure out when to fire multiple times.
I have tried looking for similar topics and asking for help on discord servers but nobody was able to help me, so I would very thankful if someone helped me figure it out!
(also the firerate is formatted in shots per minute which is why I am using 60/firerate)
local FireConnection
local Start = tick()
local LastShotTick = tick() - 60/Settings.Firerate
local Shots = 0
FireConnection = RunService.Stepped:Connect(function(dt)
if tick() - LastShotTick > 60/Settings.Firerate and tick() - Start < 60 then
--Fire weapon
LastShotTick += 60/Settings.Firerate
end
if not Active then
FireConnection:Disconnect()
end
end)
You could move the actual “shooting” bit to the server. Then you tell when you start firing and when you stop firing. This also helps preventing exploiters from firing the gun more than it’s supposed to/having infinite ammo.
You can keep your current code for effects like bullet tracers which don’t matter as much.
Yeah I’m planning on doing that and I got an idea of how I can do it with lag compensation and stuff but the server still runs at 60 fps max which would still result in the same issue
Yeah the server does have more consistent framerate which allows the weapon to fire 60 time per second, but if I want the weapon to have more than 60 shots per second it would result in shots that weren’t fired cause the server has 60 fps
You could double the damage to compensate for that if you want the gun to fire that fast. Also are you making a laser weapon? Why would you need to fire that fast in the first place?
My scripts are optimized, I want to add this compensation for weapons such as a minigun which have an insane rate of fire of up to 6000rpm which results in roughly 100 shots per second