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

What's wrong with this armory script?

Upgrade=function(Player, Ammo, Damage)
	if Player and Ammo and Damage then
		local BP,SG,BPGUN,SGGUN=Player:findFirstChild("Backpack"),Player:findFirstChild("StarterGear"),BP:findFirstChild("Gun"),SG:findFirstChild("Gun")
		repeat wait(.15) until BP and SG and BPGUN and SGGUN
		BPGUN["Stats"]["Ammo"].Value=Ammo
		SGGUN["Stats"]["Ammo"].Value=Ammo
		BPGUN["Stats"]["Damage"].Value=Damage
		SGGUN["Stats"]["Damage"].Value=Damage
	end
end

That's just the snippet of code that's erroring. It goes with an armory system with an onTouched function. Whenever I touch the brick, it's supposed to find my Backpack and StarterGear, but so far all I've gotten in the Output is Workspace.ArmoryControl:3: attempt to index global 'BP' (a nil value)

Why is it saying that? I've looked BP over and I can't seem to find why it can't find BP. How would I be able to fix it?

Thank you!

2 answers

✓ Accepted answer

The problem is that you defined so much things in just one line.

Relace line 3 with:

local BP = Player:FindFirstChild("Backpack")
local SG = Player:FindFirstChild("StarterGear")
local BPGUN = BP:FindFirstChild("Gun")
local SGGUN = SG:FindFirstChild("Gun")

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