Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make it reload one per use ?

Ok so this is a Ammo refill script for Gun ammo capacity IT IS NOT A RELOAD SCRIPT, it reinforces the amount of ammo that gun has in reserve And I have a problem with it:

When activated It reinforces all guns that are listed in GunToRefillAmmo

while I want it to reinforce one gun per use (it doesn't reinforce 2 guns with same name so that's ok)

The problem seems to be around the For loop or Array

Just can't figure out how to fix it

local AmmoBox = script.Parent
local Enabled = true

--==================================================
--Setting
--==================================================
local Ammo = 20 --Amount of Ammo to give. Set it to "math.huge" to refill the gun's ammo.
local GunToRefillAmmo = {
	"Obrez","Kaban", "MP-Obrez",
	--Add more gun here if you want
}
--==================================================

local function Enablerx2(Activated)
	local AmmoRefilled = false
	local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
			for i, GunName in  pairs(GunToRefillAmmo) do
				local Gun = Player.Backpack:FindFirstChild(GunName) or Player.Character:FindFirstChild(GunName)
				if GunName 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
					local ChangedAmmo = (GunScript.Ammo.Value + Ammo)
					GunScript.Ammo.Value = ChangedAmmo
					local Mag = GunScript.Mag.Value
					GunScript.ChangeMagAndAmmo:FireClient(Player,Mag,ChangedAmmo)
					AmmoRefilled = true
						end
					end
				end
		if AmmoRefilled then AmmoBox:Destroy() end
	end
end
script.Parent.Activated:Connect(Enablerx2)

2 comments

0

Is this your script?

0

Define "one at a time". For more information see https://idownvotedbecau.se/UnclearQuestion

1 answer

I just found out I needed to put a break somewhere down the line to stop the for loop Solved the issue

This discussion is preserved as it was. New answers, comments, and votes are closed.