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

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

Log in to vote
0
Answered by
XAXA 1569 Moderation Voter
6 years ago

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

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.. LuckyAura -1 — 6y
Ad

Answer this question