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

How do I make a GUI appear only when a tool is selected?

Asked by 10 years ago

And it would only be appearing when the tool is selected. It will be gone when you deselect the tool or when you haven't selected it (just clarifying.)

2 answers

Log in to vote
0
Answered by 10 years ago

You can put this in a hopperbin. Put the GUI in the hopperbin and name it 'Main_Gui' Also make sure that it's a local script.

This creates/removes the GUI each time you select/deselect the tool.

local tool = script.Parent
local guiMain = tool['Main_Gui']
local guiClone = nil


local select = function()
    if guiClone then return end
    guiClone = guiMain:Clone()
    guiClone.Parent = game.Players.LocalPlayer.PlayerGui
end

local deselect = function()
    if guiClone then guiClone:Destroy() end
end

tool.Selected:connect(select)
tool.Deselected:connect(deselect)

Ad
Log in to vote
0
Answered by 10 years ago

You would use the hopperbin's Selected and Deselected properties, When selected you could set the gui's Visible property to true, and when deselected you could set the gui's Visible property to false.

Tool.Selected:connect(function()
    Gui.Visible = true
end)
Tool.Deselected:connect(function()
    Gui.Visible = false
end)

Answer this question