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

Attempt to index local 'gui' (a nil value?)

Asked by 6 years ago
Edited 6 years ago

Please help, I'm trying to get a GUI to open when a tool is selected but it isn't opening at all. :-(

I get this error when I open the tool: OpenGUI:9: Attempt to index local 'gui' (a nil value), Line 9 - global LoadGui, Line 23

And this error when I close the tool: BenOVGui is not a valid member of PlayerGui, Line 18 - global UnloadGui, Line 18, Line 27

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

function LoadGui()
    repeat wait() until player.Character 
    if not player.PlayerGui:FindFirstChild("BenOVGUI") then
        local cgui = game:GetService("ReplicatedStorage"):WaitForChild("BenOVGUI")
        gui = cgui:Clone()
        gui.Parent = playerGui <--
        print("Gui placed in ".. player.Name) 
    else 
        player.PlayerGui.BenOVGUI.Enabled = true
        print("Gui Enabled.")
    end
end

function UnloadGui()
    playerGui.BenOVGUI.Enabled = false <--
    print("Gui Disabled.")
end

script.Parent.Parent.Equipped:connect(function()
    LoadGui() <--?
end)

script.Parent.Parent.Unequipped:connect(function()
    UnloadGui() <--?
end)
0
Please help? LuckyAura -1 — 6y
0
When I ran the code, it worked perfectly fine. Try restarting studio maybe. User#17862 0 — 6y
0
Really? In studio it shows no errors and does nothing. In game, it shows those errors.. :/ LuckyAura -1 — 6y
0
I just tried it in game and it works fine too. User#17862 0 — 6y
0
I'm using Adonis Admin and it screwed with the way I had it before. I'm getting the errors with it but I really like the admin. If you add it in you'll get the errors. LuckyAura -1 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Um, well here's a more efficient code that I used:

local replicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
playerGui = player.PlayerGui
local tool = script.Parent

function LoadGui()
    local BenOVGUI = playerGui:FindFirstChild("BenOVGUI")
    if BenOVGUI then
        BenOVGUI.Enabled = true
    else
        local cgui = replicatedStorage:WaitForChild("BenOVGUI")
        local gui = cgui:Clone()
        gui.Parent = playerGui
        gui.Enabled = true
    end
end

function UnloadGui()
    local BenOVGUI = playerGui:FindFirstChild("BenOVGUI")
    if BenOVGUI then
        BenOVGUI.Enabled = false
    end
end

tool.Equipped:connect(function(mouse)
    LoadGui()
end)

tool.Unequipped:connect(function()
    UnloadGui()
end)

I've tested it out and had no problems, so it could really either be that your object directories are wrong or the gui is named differently.

0
Yes, it has a part called Handle. LuckyAura -1 — 6y
0
I'm using Adonis Admin and it screwed with the way I had it before. I'm getting the errors with it but I really like the admin. If you add it in you'll get the errors. LuckyAura -1 — 6y
0
Edited ^ dpark19285 375 — 6y
0
I'm getting the attempt to index local 'gui' (a nil value) error with Line 15 - global LoadGui, Line 28 LuckyAura -1 — 6y
View all comments (3 more)
0
Please help! LuckyAura -1 — 6y
0
That means the script couldn't find anything named BenOVGUI in the ReplicatedStorage. Try checking if your directories and names are word for word correct dpark19285 375 — 6y
0
Except.. there is a gui named BenOVGUI in ReplicatedStorage. LuckyAura -1 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

If you mean when a tool is equipped, i think this will work :-) put this in a localscript in startergui and change line 2 to the gui you want to make visible and change BigSword to the tool name

game.Workspace:WaitForChild(game.Players.LocalPlayer.Name):WaitForChild("BigSword") --Change to tool name
script.Parent.ScreenGui.TextLabel.Visible = true

Hope it works, if not tell me and ill try to fix it :)

0
this should work, why dont you use it? lukebloxdaily 6 — 6y

Answer this question