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
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)