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

Whats this error from OutPut mean?{Unsolved!}

Asked by 10 years ago

Error:15:18:16.560 - Players.Player1.PlayerGui.MainShop.MainShop.Frame.Assault R:19: attempt to index global 'GuiButtonPath' (a nil value) Full script: vvvvvv

local player = game.Players.LocalPlayer --This only works in a local script.
cost = 0 --assign the cost of the AssaultRifle here.

function checkForAssaultRifle()
    for i, v in pairs(player.Backpack:GetChildren()) do
        if v.Name == "AssaultRifle" then
         return true
        end
    end
    for i, v in pairs(player.Character:GetChildren()) do
        if v.Name == "AssaultRifle" then
          return true
        end
    end
    return false
end


GuiButtonPath.MouseButton1Click:connect(function()
    local needsAssaultRifle = not checkForAssaultRifle() --needsAssaultRifle is the opposite of found.
    local leaderstats = player:FindFirstChild("leaderstats")
    if leaderstats ~= nil then
        local Money = leaderstats:FindFirstchild("Money")
        if Money ~= nil then
            if Money.Value >= cost and needsAssaultRifle then --if they have the money and they need a AssaultRifle
                Money.Value = Money.Value - cost --subtract cost from funds
                AssaultRifle = game.Lighting.AssaultRifle:Clone()
                AssaultRifle.Parent = player.Backpack --give them a AssaultRifle
            end
        end
    end
end)

It was working earlier, and I know the cost isn't the problem, it just stopped working after I change the previous items name with 'AssaultRifle'. Thanks!

1
What is wrong with it? And you should be telling US the error. Debug before you come here okay, use output. Lacryma 548 — 10y
0
15:18:16.560 - Players.Player1.PlayerGui.MainShop.MainShop.Frame.Assault R:19: attempt to index global 'GuiButtonPath' (a nil value) nightmare13542 45 — 10y

3 answers

Log in to vote
2
Answered by
Lacryma 548 Moderation Voter
10 years ago

The problem is that you are returning it wrong. Use this way instead, it's hard to explain clearly. Hopefully someone will be able to put it into words.

local player = game.Players.LocalPlayer --This only works in a local script.
cost = 0 --assign the cost of the AssaultRifle here.

function checkForAssaultRifle()
    for i, v in pairs(player.Backpack:GetChildren()) do
        if v.Name == "AssaultRifle" then
         return true
        end
    end
    for i, v in pairs(player.Character:GetChildren()) do
        if v.Name == "AssaultRifle" then
          return true
        end
    end
    return false
end


GuiButtonPath.MouseButton1Click:connect(function()
    local needsAssaultRifle = not checkForAssaultRifle() --needsAssaultRifle is the opposite of found.
    local leaderstats = player:FindFirstChild("leaderstats")
    if leaderstats ~= nil then
        local Money = leaderstats:FindFirstchild("Money")
        if Money ~= nil then
            if Money.Value >= cost and needsAssaultRifle then --if they have the money and they need a AssaultRifle
                Money.Value = Money.Value - cost --subtract cost from funds
                AssaultRifle = game.Lighting.AssaultRifle:Clone()
                AssaultRifle.Parent = player.Backpack --give them a AssaultRifle
            end
        end
    end
end)
0
Thanks! nightmare13542 45 — 10y
0
Still not working... Hmm. nightmare13542 45 — 10y
0
15:18:16.560 - Players.Player1.PlayerGui.MainShop.MainShop.Frame.Assault R:19: attempt to index global 'GuiButtonPath' (a nil value) This comes up.... nightmare13542 45 — 10y
0
One month late response sorry, but you need to define GuiButtonPath. I'm sure you got it by now. Lacryma 548 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Make sure you have GuiButtonPath as a variable in the script, or the script will have no idea what you're talking about. Do something like this:

local GuiButtonPath = script.Parent.GuiButtonPath

If you don't have GuiButtonPath as a variable in the script, the script doesn't have a way of identifying what GuiButtonPath is

0
Thanks, but it still won't work. I'll just get a free model and change the size/color/position to that of my current GUI. ;-; nightmare13542 45 — 10y
Log in to vote
-1
Answered by 10 years ago

Is GuiButtonPath in AssaultRifle?

0
No... nightmare13542 45 — 10y

Answer this question