Hello! I’m working on a gun script, and I’m adding reloading. However I seem to be very subpar at math. Even with the computer doing it all for me, I’m sure this is relatively easy and I’m just dumb.
The player is able to reload twice if they use r and click while they have no ammo to reload. The players total ammo can go negative, which causes the players actual ammo to also go negative.
I’ve looked it up, however I didn’t see anything probably because it’s some simple math or something.
Here is my reloading function
local function Reload()
local reloadanim = hum:LoadAnimation(animr)
reload.Playing = true
local spentammo = maxammo - ammo.Value
local ghostclip
totalammo.Value -= spentammo
ghostclip = ammo.Value + spentammo
if totalammo.Value <= 17 then
canReload = false
reloadanim:Play()
wait(2.647)
ammo.Value = totalammo.Value
reloadanim:Stop()
canReload = true
return
end
if ghostclip <= 0 then
return
end
canReload = false
reloadanim:Play()
wait(2.647)
ammo.Value += spentammo
reloadanim:Stop()
canReload = true
return
end
Thanks in advance.