I am currently creating a gun script and there is two values; CurrentAmmo
and MaxAmmo
. I created this portion of the script:
mouse.Button1Down:Connect(function() if enableMouse == true then isFull = false currentAmmo.Value = currentAmmo.Value - 1 print(currentAmmo.Value) realFrame:TweenSize(UDim2.new(1,0,currentAmmo.Value / maxAmmo.Value),'In','Sine',.1) game.StarterPlayer.Fire:Play() if currentAmmo.Value <= 0 then reload = true gunSound.SoundId = emptyAmmoSound backgroundFrame.TextLabel.Visible = true realFrame.BackgroundColor3 = Color3.fromRGB(255,0,0) currentAmmo.Value = 0 end end end)
However, the CurrentAmmo
keeps going down until negative, despite the script telling it not to.
Any help please?
Try this:
if enableMouse == true and currentAmmo.Value<=0 then
I personally believe that little change could help.
The CurrentAmmo turns negative because there is nothing stopping it from doing so. The reload scripts returns the value to zero but only after the gun is fired. I suggest putting the reload script before the event is fired.
Edit kinda late but if you still need it
mouse.Button1Down:Connect(function() if enableMouse == true then if currentAmmo.Value > 0 then isFull = false currentAmmo.Value = currentAmmo.Value - 1 print(currentAmmo.Value) realFrame:TweenSize(UDim2.new(1,0,currentAmmo.Value / maxAmmo.Value),'In','Sine',.1) game.StarterPlayer.Fire:Play() else reload = true gunSound.SoundId = emptyAmmoSound backgroundFrame.TextLabel.Visible = true realFrame.BackgroundColor3 = Color3.fromRGB(255,0,0) currentAmmo.Value = maxAmmo.Value end end end)