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

What's wrong with this script?

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

0

try :remove()

0

no never try remove remove is bad remove is horrible remove is depricated.

0

check if guimain isn't nil.

1 answer

I removed the "local" in front of "local guiMain" on line 7 and fixed it. :)

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