Weird bug in my modified fe gun kit

The bug I am currently experiencing is a bug about the ammo. There is different ammo bags for different guns. And now apparently, If you use the ammo bag on a weapon, reload it till it shows +1 at the mag (And yes, my modified fe gun kit features a extra bullet in the chamber for realism) and then uses another ammo bag, the gun will not lose any single bullet from its mag after firing. Can anyone help me? Here’s the script for the part that gives ammo:

local AmmoBox = script.Parent
local Enabled = true

--==================================================
--Setting
--==================================================
local Ammo = 90 --Amount of Ammo to give. Set it to "math.huge" to refill the gun's ammo.
--  Ammo doesnt matter anymore, it just refills the ammo instantly but not the mag. Weird, Right?
local Cooldown = 60
local GunToRefillAmmo = {
	"AKMS", "SKS"
}
--==================================================

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 + 1 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.MaxAmmo or (GunScript.Ammo.Value + Ammo)
							--GunScript.Ammo.Value = GunScript.Ammo.Value + Ammo
							GunScript.ChangeMagAndAmmo:FireClient(Player,GunScript.Ammo.Value,ChangedAmmo, GunScript.Mag.Value)
							AmmoBox:Destroy()
						end
					end
				end
			end
		end
	end
end
AmmoBox.Touched:connect(Enabler)

I’ve modified the code myself, long time ago and now I think it’s buggy (thanks to me). Can anyone help me out why this is happening? I’ll provide anything that I can

2 Likes

I Fixed it myself no having to reply guys

1 Like