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

Trying to make a GUI appear and disappear when equipping a tool. Help?

I'm trying to make a GUI appear when you equip a tool and have the GUI disappear when you unequip the tool.

I've tried everything I've could think of. I finally got one step working and then it failed on me. It opens, but it will not close.

local tool = script.Parent
local gui

local function readMenu()
	local player = game.Players:getPlayerFromCharacter(tool.Parent)
	if player.PlayerGui:findFirstChild("Menu") == nil then
		gui = tool.Menu:Clone()
		gui.Parent = player.PlayerGui
	end
end

local function closeMenu()
	wait()
	if gui then gui:Menu() end
end

tool.Equipped:connect(readMenu)
tool.Unequipped:connect(closeMenu)

1 comment

0

In the variables you forgot to give a value to gui

1 answer

You are trying to call a method on "gui".

-- LocalScript

local player = game.Players.LocalPlayer
local tool = script.Parent
local menuScreenGui = tool:WaitForChild('Menu')
local playerGui = player:WaitForChild("PlayerGui")
-- gui = (The menu already in my PlayerGui OR do we need to make one?)
local gui = playerGui:findFirstChild("Menu") or menuScreenGui:Clone()
local menu_frame = gui:WaitForChild("Frame") -- what you're actually making visible
gui.Parent = playerGui

local function readMenu()
    menu_frame.Visible = true
end

local function closeMenu()
    menu_frame.Visible = false
end

tool.Equipped:connect(readMenu)
tool.Unequipped:connect(closeMenu)

1 comment

0

Thanks so much, it works! (:

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