local function p(p)if Enabled and(p and p.Parent)then local J=false local v=game.Players:GetPlayerFromCharacter(p.Parent)if v then for p,A in pairs(GunToRefillAmmo)do local d=v.Backpack:FindFirstChild(A)or v.Character:FindFirstChild(A)if d then local p=d:FindFirstChild("\071\117\110\083\099\114\105\112\116\095\083\101\114\118\101\114")local A=d:FindFirstChild("\083\101\116\116\105\110\103")if p and A then local d=require(A)if p.Ammo.Value<d.MaxAmmo and d.LimitedAmmoEnabled then if Cooldown~=0 then Enabled=false AmmoBox.Sound:Play()AmmoBox.Transparency=1 AmmoBox.CanCollide=false AmmoBox.SurfaceGui.Enabled=false local function p()AmmoBox.Transparency=0 AmmoBox.CanCollide=true AmmoBox.SurfaceGui.Enabled=true Enabled=true end delay(Cooldown,p)else AmmoBox.Sound:Play()end J=true local A=(Ammo==math.huge or p.Ammo.Value+Ammo>=d.Ammo)and d.Ammo or p.Ammo.Value+Ammo p.Ammo.Value=A p.ChangeMagAndAmmo:FireClient(v,d.AmmoPerMag,A)end end end end end end end AmmoBox.Touched:connect(p)


local function Enabler(Hit)
	if Enabled and Hit and Hit.Parent then
		local AmmoRefilled = false
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		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.Sound:Play()
								AmmoBox.Transparency = 1
								AmmoBox.CanCollide = false
								AmmoBox.SurfaceGui.Enabled = false
								local function delayer()
									AmmoBox.Transparency = 0
									AmmoBox.CanCollide = true
									AmmoBox.SurfaceGui.Enabled = true
									Enabled = true
								end
								delay(Cooldown,delayer)
							else
								AmmoBox.Sound:Play()
							end
							AmmoRefilled = true
							local ChangedAmmo = (Ammo == math.huge or GunScript.Ammo.Value+Ammo >= Module.Ammo) and Module.Ammo or (GunScript.Ammo.Value + Ammo)
							GunScript.Ammo.Value = ChangedAmmo
							GunScript.ChangeMagAndAmmo:FireClient(Player,Module.AmmoPerMag,ChangedAmmo)
						end
					end
				end
			end
		end
	end
end
AmmoBox.Touched:connect(Enabler)
