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)
You need to add this: script.Parent.Parent.AllAmmo.Value == 0 to script.
--Fixed Code: 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 or script.Parent.Parent.AllAmmo.Value == 0 then --Here 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)
If still doesn't works, Post a comment.