if my braincells are working rn from what i see the tool’s ammo is immediately being set to the maximum so the precondition if statement never runs, so the actual StoredAmmo value never gets updated and no shell inserts happen, so just remove the first line in the reload function
spoon feed
function Reload()
Tool.Ammo.Value = Tool.MaxAmmo.Value
if ...
end
Well it still didn’t reload, BUT it did reload when I accidentally made the Ammo value less than MaxAmmo, for example Ammo = 8, MaxAmmo = 10. But it only reloads one shell, and it doesnt work anymore
i’ve refactored and edited the code a little bit to the best of my ability, maybe it’ll fix it since it is pretty old
function Reload()
if script.Parent.Ammo.Value < script.Parent.MaxAmmo.Value and not reloading and script.Parent.StoredAmmo.Value >= 1 then
reloading = true
local neededAmmo = script.Parent.MaxAmmo.Value - script.Parent.Ammo.Value
local availableAmmo = script.Parent.StoredAmmo.Value
local ammoToReload = math.min(neededAmmo, availableAmmo)
script.Parent.StoredAmmo.Value -= ammoToReload
script.Parent.Ammo.Value += ammoToReload
ShellInsert()
reloading = false
end
end
Okay I got a script that can finally reload the gun. But theres another problem that is it will reset the ammo to 0, so it will always reload the amount of maxammo you have even tho you still have bullets. For example, you have 7 ammo but the gun reloads 8 times still
function Reload()
if not reloading and script.Parent.StoredAmmo.Value > 0 then
reloading = true
script.Parent.Ammo.Value = 0
wait(0.1)
while script.Parent.Ammo.Value < script.Parent.MaxAmmo.Value and script.Parent.StoredAmmo.Value > 0 do
ShellInsert()
script.Parent.Ammo.Value += 1
script.Parent.StoredAmmo.Value -= 1
wait(0.1)
end
reloading = false
end
end
Nvm, I just thought of copying and looking at another fixed old gun (to be specific, Manofthelol’s) that just happened to be semi automatic and had manual reloading.
The function would look like this
function Reload()
if script.Parent.Ammo.Value < script.Parent.MaxAmmo.Value and reloading == false and script.Parent.StoredAmmo.Value >= 1 then
reloading = true
for i = 1,script.Parent.MaxAmmo.Value - script.Parent.Ammo.Value do
if canclereloading == true then
canclereloading = false
break
end
-- ...
ShellInsert()
if script.Parent.StoredAmmo.Value >= 1 then
script.Parent.Ammo.Value = script.Parent.Ammo.Value + 1
script.Parent.StoredAmmo.Value = script.Parent.StoredAmmo.Value - 1
end -- this is getting annoying, and its not even half way done (thats from the original creator probably)
task.wait(.1)
end
reloading = false
end
end