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 when a tool is equipped ?

I have absolutely no clue how to do this but I really need to know how to do it

2 answers

use the .Equipped and Unequipped events of a tool. Then, make the gui visible

EXMAPLE

Tool = game.StarterGear.Tool
Gui= game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame

Tool.Equipped:connect(function()
Gui.Visible = true
end)

-- Allows GUI to go away
Tool.Unequipped:connect(function()
Gui.Visible = false
end)

For more information, Use the rblox wiki and go to this link http://wiki.roblox.com/index.php?title=API:Class/Tool

And look at the events section

4 comments

0

would this be in a script or a local script ? sorry if im being nooby lol

0

Local script, sorry for not elaborating on that

0

im being very nooby sorry if im annoying but where do i put this local script ?

0

anywhere, i recommend starter player scripts. Workspace also works. DO NOT put in storages or the serverscript service

So I have just an example, I actually use this for my Mobile Controls Basketball.

local plr = game.Players.LocalPlayer --This is a Local Script
local playerGui = plr:WaitForChild("PlayerGui") --Better like this.
local controlGuiClass = script.Parent.ControlsGUI
local tool=script.Parent

--What I did was put the GUI inside the Tool.

tool.Equipped:connect(function()
	local CGClone = controlGuiClass:Clone() 
	CGClone.Parent = playerGui --Transfer the Cloned GUI into the Player's GUI.
	CGClone.TextButton.Visible = true --I have my Visibility turned off, so I manually turn it on in this script.
end)

tool.Unequipped:Connect(function()
	if playerGui:FindFirstChild("ControlsGUI") then -- B/c it'll check the original variable, which you'll have to have the script
		playerGui.ControlsGUI:Destroy()
	end
end)

--Whenever you Unequip that tool, the GUI would be destroyed, meaning if you didn't have the Unequipped function, you would have a GUI still on your screen lol.

Also you could put it inside the Replicated Storage, but this method up here is more efficient, at least that's what I think.

Hopefully this helps, LukeGabrieI

4 comments

0

Which parts would i change to make it fit my game. Would I have to change all the control things or what ?

0

Basically lol.

0

Luke, I know this is an old post, but I need your help! The equipped function part works, but not the unequipped function, I've tried everything I dont know that to do, help plz

0

Queen, I know this is an old reply but you can try turning off required handle

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