Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a way to make roblox calculate ammo amount?

I'm making a lever action rifle, and when you press "r" you will reload. Is there a way to make roblox do the math on how many rounds to reload, then play the reload animation each time?

2 comments

0

yes

0

Check the scripts or IntValues.

2 answers

This is how I do it

local currentAmmo = script:WaitForChild("Current")
local reserveAmmo = script:WaitForChild("Reserve")

local ammoToUse = math.min(AMMO_CAPACITY - currentAmmo.Value, reserveAmmo.Value)
currentAmmo.Value = currentAmmo.Value + ammoToUse
reserveAmmo.Value = reserveAmmo.Value - ammoToUse

This is just a snippet of my code, btw

2 comments

0

Can I get more code? Like if you had 6 ammo left and your gun had a capacity of 12, it would still take 12 anyway

0

for me it only uses 6

local MaxAmmo = 12
local CurrentAmmo = 0

-- this is when you have no more bullets and you wanna insert each bullet

for I = 1, (MaxAmmo - CurrentAmmo) do
	print('bullet loaded')
end
-- reloads bullet 12 times

This discussion is preserved as it was. New answers, comments, and votes are closed.