1

# How to stop code if IntValue is below a number?

I'm VERY new at coding and was trying to make a gun system in roblox. Right now I'm trying to make an ammo system. it works fine and counts down the bullets until 0 at witch point it will keep going into the negatives. I've tried using if statements but no matter where i put it, it doesn't seem to do anything.

Ammo = game.StarterPack["Deagle 44"].Ammo.Value

if Ammo < 1 then print("out")

deb = false

function onActivation()

if deb then return end -- start cooldown
deb = true

game.SoundService.Shot:Play(1) -- play shot sound
Ammo = Ammo - 1
print(Ammo)

wait(0.5) -- cooldown time

deb = false -- end cooldowm
end
end

game.Players.LocalPlayer.Backpack["Deagle 44"].Activated:Connect(onActivation)


0
Edited 1 year ago
local Ammo = game.StarterPack["Deagle 44"].Ammo.Value

local deb = false

function onActivation()
if not deb and Ammo > 0 then
deb = true

game.SoundService.Shot:Play(1)
Ammo = Ammo - 1
print(Ammo)

wait(0.5)

deb = false
end
end

game.Players.LocalPlayer.Backpack["Deagle 44"].Activated:Connect(onActivation)


This should fix it.

0
THANK YOU SO MUCH THIS ACTUALLY WORKED phantomforcesdeath 9 — 1y