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

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

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: Attempt to index local 'gui' (a nil value), Line 15 - global LoadGui, Line 28

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)

1 answer

Is cgui Archivable by any chance? Anything that is not Archivable cannot be cloned.

1 comment

0

It was, but I was able to have it cloned while still being Archivable before. I added in Adonis Admin to my game and it broke the script, and it's giving me errors but I really like the admin so..

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