Ammo Box Help (value and basic scripting)

Did you look at the value before and after you ran the script?
Edit: and max ammo is a int value or number value?

it’s a numbervalue and i’m not sure i understand your first question

what happened

also this happens when i add the “end)” at the for i part

script.Parent.MouseClick:Connect(function(plr)
	for _,tool in ipairs(plr.Backpack:GetChildren()) do

		local MaxAmmo = tool:FindFirstChild("MaxAmmo")

		if tool:IsA("Tool") and MaxAmmo then
print(MaxAmmo.Value)
			MaxAmmo.Value += 12
			print(MaxAmmo.Value)
		end
	end
end)

And see if the print’s value changes.
(The script above is where click detector is the parent of the script)

nothing even happened. i clicked it with the gun unequipped and same problem. there was nothing in the output and the MaxAmmo value didn’t change at all

Well it works for me so that’s confusing.

wait maybe because it doesn’t work cause i unequip

Wait…it’s in the character, not in the player (the tool) that’s why is isn’t working.

oh yeah i use this give part to give the tool to the player.

it still doesn’t work even if it put it in starterpack

It should be putting the tool in the player’s backpack, not in the character.

how do i fix that?

the code is still

script.Parent.MouseClick:Connect(function(plr)
	for _,tool in ipairs(plr.Backpack:GetChildren()) do

		local MaxAmmo = tool:FindFirstChild("MaxAmmo")

		if tool:IsA("Tool") and MaxAmmo then
			print(MaxAmmo.Value)
			MaxAmmo.Value += 12
			print(MaxAmmo.Value)
		end
	end
end)

What’s the code for the tool giver?

local Detector = script.Parent.ClickDetector
local Tool = game.ServerStorage.G16A1
local Part = script.Parent

Detector.MouseClick:Connect(function(Player)
local Clone = Tool:Clone()
Clone.Parent = Player.Character
Part:Destroy()
end)

Make it this:

local Detector = script.Parent.ClickDetector
local Tool = game.ServerStorage.G16A1
local Part = script.Parent

Detector.MouseClick:Connect(function(Player)
local Clone = Tool:Clone()
Clone.Parent = Player.BackPack
Part:Destroy()
end)

If you keep the giver script the same make the box script this:

script.Parent.MouseClick:Connect(function(plr)
	for _,tool in ipairs(plr.Character:GetChildren()) do

		local MaxAmmo = tool:FindFirstChild("MaxAmmo")

		if tool:IsA("Tool") and MaxAmmo then
			MaxAmmo.Value += 12
		end
	end
end)

the giver brick script doesn’t work

Whoops, it’s “Backpack”, not “BackPack”

it destroys the part but doesn’t give the tool inside the inventorhy.

edit: nvm it was just the custom inventory gui that made it not work