• Register a free account to view all forum content. Click here to create your own account.

Gun ammo issue, I am losing way more ammo than what the script says to lose, why?

Joined
Jan 2, 2019
Messages
12
Roblox
HeyItzDanniee
So, I made a simple gun. It contains:
ServerScript
LocalScript.
ModuleScript.
x2 RemoteEvents.
Handle with sound effects.
Main with more sound effects and particles.


How It Works:
I am using the LocalScript as an Input script.. so whenever I equipt the gun, it sets the "out" property to true, meaning now I can shoot - that means whenever I press the mouse button, the script fires a "ShootRemote" (one of the 2 remotes), to the ServerScript. Everything else is handled in there: shooting, reloading, animations, particles (I made it so everyone will see the particles and light effects).
Now, the ModuleScript contains the settings of the gun: ammo, clipsize.

The Issue:
Whenever I fire my gun, it works fine. I can shoot MAX 15 bullets (its a handgun). The 15 bullets are a setting in the ModuleScript. However, when I unequipt the gun, and equipt it again, reload it, then when I shoot it, suddenly it wont shoot 15 bullets.. it would shoot less. If I do it again: unequipt > equipt > reload > shoot, It would shoot even more less bullets. I have no idea why. The script tells the gun to shoot it only once and remove only 1 bullet per shot.

Similar Issue:
There is something similar to that, that happened to me. I made a gun but with values inside the gun, not a ModuleScript (it was when I was a noob with modules). and it happened again.. unequipt, equipt, reload and shoot. But back then I could check the values.. when I did.. I saw that the bullets go like this: 30, 28, 26, 24, 22.
Each time I shoot, 2 bullets were lost. When I unequipt, equipt, reload and shot again, 3 bullets were lost per shot.

Anyone knows why tso many bullets get removed when the script tells to remove only one? Please help. :c
Post automatically merged:

function shoot(player)

local char = player.Character

local hum = char.Humanoid

local came = game.Workspace.Camera

local recoilanim = hum:LoadAnimation(anims.recoil)

if s.ammo > 0 then

main.Fire:Play()

main.Flash.Enabled = true

main.PointLight.Enabled = true

recoilanim:Play()

s.ammo = s.ammo - 1

wait(0.1)

main.Flash.Enabled = false

main.PointLight.Enabled = false

recoilanim:Stop()

end

end
 
Last edited:

CallMeKY

Active Member
Joined
Feb 25, 2018
Messages
387
Ratings
115
Roblox
CallMeKY
Discord
CallMeKY#5012
So, I made a simple gun. It contains:
ServerScript
LocalScript.
ModuleScript.
x2 RemoteEvents.
Handle with sound effects.
Main with more sound effects and particles.


How It Works:
I am using the LocalScript as an Input script.. so whenever I equipt the gun, it sets the "out" property to true, meaning now I can shoot - that means whenever I press the mouse button, the script fires a "ShootRemote" (one of the 2 remotes), to the ServerScript. Everything else is handled in there: shooting, reloading, animations, particles (I made it so everyone will see the particles and light effects).
Now, the ModuleScript contains the settings of the gun: ammo, clipsize.

The Issue:
Whenever I fire my gun, it works fine. I can shoot MAX 15 bullets (its a handgun). The 15 bullets are a setting in the ModuleScript. However, when I unequipt the gun, and equipt it again, reload it, then when I shoot it, suddenly it wont shoot 15 bullets.. it would shoot less. If I do it again: unequipt > equipt > reload > shoot, It would shoot even more less bullets. I have no idea why. The script tells the gun to shoot it only once and remove only 1 bullet per shot.

Similar Issue:
There is something similar to that, that happened to me. I made a gun but with values inside the gun, not a ModuleScript (it was when I was a noob with modules). and it happened again.. unequipt, equipt, reload and shoot. But back then I could check the values.. when I did.. I saw that the bullets go like this: 30, 28, 26, 24, 22.
Each time I shoot, 2 bullets were lost. When I unequipt, equipt, reload and shot again, 3 bullets were lost per shot.

Anyone knows why tso many bullets get removed when the script tells to remove only one? Please help. :c
Post automatically merged:

function shoot(player)

local char = player.Character

local hum = char.Humanoid

local came = game.Workspace.Camera

local recoilanim = hum:LoadAnimation(anims.recoil)

if s.ammo > 0 then

main.Fire:Play()

main.Flash.Enabled = true

main.PointLight.Enabled = true

recoilanim:Play()

s.ammo = s.ammo - 1

wait(0.1)

main.Flash.Enabled = false

main.PointLight.Enabled = false

recoilanim:Stop()

end

end
This seems a little vague to me, it would be easier to help with more to go on. Also, please format your code so it's easier to read.
Code:
function shoot(player)
    local char = player.Character
    local hum = char.Humanoid
    local came = game.Workspace.Camera
    local recoilanim = hum:LoadAnimation(anims.recoil)
    if s.ammo > 0 then
        main.Fire:Play()
        main.Flash.Enabled = true
        main.PointLight.Enabled = true
        recoilanim:Play()
        s.ammo = s.ammo - 1
        wait(0.1)
        main.Flash.Enabled = false
        main.PointLight.Enabled = false
        recoilanim:Stop()
    end
end