So i'm making a gun and it's going good but i have a problem where if all of the ammo is a certain number then it's possible for it to go to the negatives. I've tried using math.floor but that didn't really work for me. I also tried checking the number with an if statement but it's really confusing and i don't really know how to fix it! Any help at all would be nice
Here is the part of the script that reloads which is where it needs fixing.
uis.InputBegan:Connect(function(input)
if script.Parent.Parent.Parent == char then
if input.KeyCode == Enum.KeyCode.R then
if script.Parent.Parent.Ammo.Value ~= script.Parent.Parent.MaxAmmo.Value and script.Parent.Parent.AllAmmo.Value > 0 then
if reloaddebounce == false then
reloaddebounce = true
script.Parent.Parent.Sounds.Reload:Play()
reload:Play()
wait(3)
script.Parent.Parent.Ammo.Value = script.Parent.Parent.MaxAmmo.Value
script.Parent.Parent.AllAmmo.Value = script.Parent.Parent.AllAmmo.Value - script.Parent.Parent.AmmoLost.Value
script.Parent.Parent.AmmoLost.Value = 0
reloaddebounce = false
end
end
end
end
end)

1 comment
Why are you refercing two different values for your ammo? You reference Ammo.Value for one and AllAmmo.Value for the other. I'm assuming these mean different things because you reference both later on. You should add another and statement checking if script.Parent.Parent.Ammo.Value is greater than 0.