When a tool is equipped, the Gui clones and the player can see it. That works fine. The problem is that when it's unequipped, it doesn't destroy the Gui. On the output it says something like "attempted to index guiMain, a nil value". Anyone know how to fix this?
Tool = script.Parent
guiMain = nil
function onEquippedLocal()
local character = script.Parent.Parent
local player = game.Players:GetPlayerFromCharacter(character)
local guiMain = script.Parent.AirportControl:clone()
guiMain.Parent = player.PlayerGui
end
function onUnequippedLocal()
guiMain:Destroy()
end
Tool.Equipped:connect(onEquippedLocal)
Tool.Unequipped:connect(onUnequippedLocal)

3 comments
try :remove()
no never try remove remove is bad remove is horrible remove is depricated.
check if guimain isn't nil.