Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What's wrong with this armory script?

Asked by 10 years ago
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

Log in to vote
1
Answered by 10 years ago

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")
Ad
Log in to vote
0
Answered by 10 years ago

BP is not defined?

0
It is, BP=Player:findFirstChild("Backpack") Devotional 210 — 10y

Answer this question