I am trying to create an M1 Garand, and when you reach one bullet and shoot it - it pings. I am trying to check when the ammo value in ModuleScript equals to one. But I am stuck.
This is my script:
local s = require(script.Parent.Module)
function shoot_gun(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:FindFirstChild("Humanoid")
local shootanim = hum:LoadAnimation(anims.Shoot)
--Shoot
if s.ammo > 0 then
--code here
elseif s.ammo == 1 then
--code here
sounds.Ping:Play() --the ping that happenes with the code
elseif s.ammo < 1 then
--code here
end
end
These are the lines I tried so far:
elseif s.ammo == 1 then --nope
elseif s.ammo < 2 and s.ammo > 0 then --nope
elseif s.ammo < 2 then --nope
elseif s.ammo < 2 > 1 then --nope, error
The shooting works but I am just trying to check when the ammo reaches one so it will just add that small sound.
The shooting code is the same but I am just adding a ping sound when the ammo is one and when I shoot and it pings it should leave me with 0 ammo and I wont be able to shoot again.
Please help, I may sound dumb because I didnt notice something but I am really stuck rn. Thank you.

5 comments
i dont understand why u doing those if statements u would only need the if statement if s.ammo => 1 or s.ammo == 1 then theres no reason to check every value
First I am checking if there is ammo in the gun to shot it. If there is ONE ammo left then it would ping cause its an M1 Garand. The shooting script is the same and it removes 1 bullet each shot but when there is 1 bullet left its gonna do the same shooting script but with a ping sound play line added.
Also "if s.ammo == 1" isnt working for me. It wont work. Even if my value has 1 the script with the ping still wont run
Your problem is with the conditional statement on line 10. 1 is greater than 0, so that statement will run and skip the others since you're using elseif, and it will keep skipping the others.
Oh, now I see. Thank you.