Full Auto gun can be spammed to shoot more than it's current ammo

This is my first attempt at a gun system and it’s non-tool based so I’ve spent a lot of time thinking about it.

My current system works like this:

Player left clicks, fires an event to the server with a true arg which changes a Shooting var to true.
If the weapon that is equipped is full auto then it’ll run this code

local Weapon = PData.Weapons[Equipped]
local Stats = Information.Weapons[Weapon.Name].Stats
for i = Weapon.Ammo, 1, -1 do
    if not PData.Shooting then 
	     Weapon.Ammo = i 
		return
	end
     print("Shot: ", i)
     wait(Stats.FireRate)
end
Weapon.Ammo = 0

PData is the players data.

If a player spam clicks left click, then this can happen though the weapon should only be shot 10 times until they run out of ammo.

I tried fixing it while adding a while loop inside a spawn, inside the for loop that checks if Shooting is false and if it is then it’ll stop it all, but it didn’t help at all.

I cannot think of another solution apart from the fact that my gun system I have in mind is terrible and not the best way to go about it.

The only thing the client does for the gun system is left click.

1 Like

cant you just have something as simple as this

local shot
local mousedown = false
local firing = false
local fireRate = 1/3
--in connection for mouse down or UIS alternative
mousedown = true
if firing or reloading then return end
firing = true
while ammo>0 and mousedown and not reloading do
    spawn(firebullet)
    ammo = ammo - 1
    shot = tick()
    repeat frame:Wait() until tick()-shot>=fireRate or reloading
end
firing = false

--disable mousedown when not clicking

note the renderstepped based wait and also the loop changes

3 Likes

Handle ammo on the client as well. Had no issues with ammo exploits even though I put ammo on the client (which is strange in itself, since that should be heavily exploitable due to its vulnerability).

PF does it too which means people can do those super fast fire rate exploits with things like sniper rifles but that is besides the point and can be prevented with rounds over time checks on server and such

2 Likes

Is there a limit to how many times you can use a remote event a minute? I was refraining from doing your method because there will be a minigun (which shoots fast) so it’d be sending a remote event to the server extremely fast.

Only fire to the server when the client starts/stops shooting.

If I do the method wunderwaffle showed me then I’ll have to fire to the server every time a bullet needs to be shot.

You have to manually replicate every bullet or else you won’t know it’s direction, unless it’s an FPS or OTS where you can infer from the character’s aim direction. There are some optimizations you can do for rapid fire weapons (e.g. minigun / smg), but not really with assault rifles / etc.

1 Like

I actually forget about needing the mouse position!

Why the frame:wait() btw instead of just wait()?

Because it would run every render step instead of every roughly .03 secs

Ah okay. What is frame btw?

renderstepped