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

How do I make a script where a GUI will show up when a tool is equipped?

Hi! I've made a script where a GUI will be enabled when a tool is equipped. The LocalScript is inserted in a tool, as the GUI is in StartGui LocalScript:

local GUI = game.StarterGui.ScreenGui

if script.Parent.Equipped == true then
	GUI.Enabled = true
end

if script.Parent.Unequipped == false then
	GUI.Enabled = false
end

1 answer

✓ Accepted answer

This is a Common Mistake

You actually want the PlayerGui, not the StarterGui service.

local plr = game.Players.LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local screenGui = plrGui:WaitForChild("ScreenGui")

if script.Parent.Equipped == true then
    screenGui.Enabled = true
end

if script.Parent.Unequipped == false then
    screenGui.Enabled = false
end

Next, this isn't connected to any event, so it'll only fire once, and never update. To fix this, lets use some events.

local plr = game.Players.LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local screenGui = plrGui:WaitForChild("ScreenGui")

local tool = script.Parent

tool.Equipped:Connect(function() -- when tool is equipped
	screenGui.Enabled = true
	tool.Unequipped:Wait() -- wait for tool to be uneqipped
	screenGui.Enabled = false
end)

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