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

What's wrong with this script?

Asked by
Sam4550 42
8 years ago

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)
0
try :remove() ghosteffectz 115 — 8y
0
no never try remove remove is bad remove is horrible remove is depricated. HungryJaffer 1246 — 8y
0
check if guimain isn't nil. HungryJaffer 1246 — 8y

1 answer

Log in to vote
0
Answered by
Sam4550 42
8 years ago

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

Ad

Answer this question