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

Whats this error from OutPut mean?{Unsolved!}

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!

2 comments

1

What is wrong with it? And you should be telling US the error. Debug before you come here okay, use output.

0

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

3 answers

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)

4 comments

0

Thanks!

0

Still not working... Hmm.

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....

0

One month late response sorry, but you need to define GuiButtonPath. I'm sure you got it by now.

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

1 comment

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. ;-;

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