--==================================================


local function Enabler(plyr)
	if Enabled then
		local AmmoRefilled = false
		local Player = plyr
		if Player then
			for _, GunName in pairs(GunToRefillAmmo) do
				local Gun = Player.Backpack:FindFirstChild(GunName) or Player.Character:FindFirstChild(GunName)
				if Gun then
					local GunScript = Gun:FindFirstChild("GunScript_Server")
					local Module = Gun:FindFirstChild("Setting")
					if GunScript and Module then
						local Module = require(Module)
						if GunScript.Ammo.Value < Module.MaxAmmo and Module.LimitedAmmoEnabled then
							if Cooldown ~= 0 then
								Enabled = false
								AmmoBox.Main.Sound:Play()
								local function delayer()
									Enabled = true
								end
								delay(Cooldown, delayer)
							else
								AmmoBox.Main.Sound:Play()
							end
							AmmoRefilled = true
							local ChangedAmmo = (Ammo == math.huge or GunScript.Ammo.Value + Ammo >= Module.Ammo) and Module.MaxAmmo or (GunScript.Ammo.Value + Ammo)
							GunScript.Ammo.Value = ChangedAmmo
							GunScript.ChangeMagAndAmmo:FireClient(Player,Module.AmmoPerMag,ChangedAmmo,0)
						end
					end
				end
			end
		end
	end
end
AmmoBox.ClickDetector.MouseClick:Connect(Enabler)
