I would like to know because I am working on a game needing this.
Use the Equipped
event of tools.
local tool = script.Parent local plr = game:GetService("Players").LocalPlayer tool.Equipped:Connect(function() plr.PlayerGui.ScreenGui.Frame.Visible = true -- assuming that's the Gui you have end)
Hello! We are going to be using the Equipped
event found in Tools for this. This must be a LocalScript
inside of a Tool
.
If you are unaware of how tools work, you can study the wiki page at http://wiki.roblox.com/index.php/Tools . But just to make your life a little easier and answer your question, I'll show you how to do it.
First we'll just assign our variables:
local tool = script.Parent -- This is the variable to access the tool faster. local gui = game.Players.LocalPlayer.PlayerGui.ScreenGui -- This is assuming you already have a ScreenGui in StarterGui. You can also change the name of the word ScreenGui at the end there to the name of the GUI that you have now.
For the next part, please make the Enabled
property in your ScreenGui
that you have in StarterGui
set to false, where everything else inside of the Gui has their Visible
set to true
unless you need it otherwise.
tool.Equipped:connect(function() gui.Enabled = true end)
If you do not already have a close button in your GUI, you will need to add this part:
tool.Unequipped:connect(function() gui.Enabled = false end)
So now, without the comments I wrote for you, your end product should look something like this:
local tool = script.Parent local gui = game.Players.LocalPlayer.PlayerGui.ScreenGui tool.Equipped:connect(function() gui.Enabled = true end) tool.Unequipped:connect(function() gui.Enabled = false end)
Please let me know if you have any questions, comments, or issues.