Ammo going to negative?

So my gun system I have been working on with FastCast is pretty much done, but I’m trying to figure out ammo. I have it to detect when the ammo is 0 but the ammo sometimes go to negatives.
Any help would be appreciated

			if script.Parent.Configuration.Ammo.Value <= 0 then
		script.Parent.Configuration.Ammo.Value = script.Parent.Configuration.Ammo.Value + 30
		CanFire = true
		end
end)

while true do
	wait()
	if script.Parent.Configuration.Ammo.Value <= 0 then
		CanFire = false
	end
end

local Ammo = script.Parent.Configuration.Ammo.Value
local MinAmmo = script.Parent.Configuration.MinAmmo.Value

Ammo.Changed:Connect(function()
    Ammo = math.clamp(MinAmmo, 0, Ammo)
end)```
1 Like

On your first line, try changing the <= to ==.

if script.Parent.Configuration.Ammo.Value ==  0 then

If the weapon fires 1 bullet at a time, this should work.
Let me know if there is any problems.

Your Ammo.Changed event won’t fire because your while loop is in the way. Move the following code to the top.

local Ammo = script.Parent.Configuration.Ammo.Value
local MinAmmo = script.Parent.Configuration.MinAmmo.Value

Ammo.Changed:Connect(function()
    Ammo = math.clamp(MinAmmo, 0, Ammo)
end)```
1 Like

Thank you everyone, but I found the solution a min after I made this forum.