I am making a lazier gun which rechargers over time if you have fired it at least once.
Here is the code I got for recognizing the guns Ammo and MagSize is lower to 6. If it is its suppose to run the loop and plus 1 onto the Ammo and MagSize values every 2 seconds till till it reaches 6 again.
local Ammo = script.Parent.Parent.Configs.Ammo.Value local MagSize = script.Parent.Parent.Configs.MagSize.Value local Tool = script.Parent.Parent Tool.Equipped:Connect(function(Recharge) if Ammo < 6 and MagSize < 6 then Recharge = true end end) while Recharge ==true do if Ammo >= 6 and MagSize >= 6 then Recharge = false else Ammo = Ammo +1 MagSize = MagSize+1 wait(2) end end
PS the value Ammo is for the gui display, while MagSize is the guns ammo. There both a set value stored in a separate folder for easy access later.
It's probably not, but it might be an issue with the variable Recharge. There are also a few ways to shorten your code:
local Tool = script.Parent.Parent local Ammo = Tool.Configs.Ammo.Value local MagSize = Tool.Configs.MagSize.Value Tool.Equipped:Connect(function() while Ammo<6 and MagSize<6 do Ammo = Ammo +1 MagSize = MagSize+1 wait(2) end end)
Also, I see that you had the recharging separate from equipping the tool, so if you still want that you could remove the Tool.Equipped event.