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

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

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

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)

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)

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