Please help, I'm trying to get a GUI to open when a tool is selected but it isn't opening at all. :-(
I get this error when I open the tool: OpenGUI:9: Attempt to index local 'gui' (a nil value), Line 9 - global LoadGui, Line 23
And this error when I close the tool: BenOVGui is not a valid member of PlayerGui, Line 18 - global UnloadGui, Line 18, Line 27
local player = game.Players.LocalPlayer local playerGui = player:WaitForChild("PlayerGui") function LoadGui() repeat wait() until player.Character if not player.PlayerGui:FindFirstChild("BenOVGUI") then local cgui = game:GetService("ReplicatedStorage"):WaitForChild("BenOVGUI") gui = cgui:Clone() gui.Parent = playerGui <-- print("Gui placed in ".. player.Name) else player.PlayerGui.BenOVGUI.Enabled = true print("Gui Enabled.") end end function UnloadGui() playerGui.BenOVGUI.Enabled = false <-- print("Gui Disabled.") end script.Parent.Parent.Equipped:connect(function() LoadGui() <--? end) script.Parent.Parent.Unequipped:connect(function() UnloadGui() <--? end)
Um, well here's a more efficient code that I used:
local replicatedStorage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") local player = Players.LocalPlayer local mouse = player:GetMouse() playerGui = player.PlayerGui local tool = script.Parent function LoadGui() local BenOVGUI = playerGui:FindFirstChild("BenOVGUI") if BenOVGUI then BenOVGUI.Enabled = true else local cgui = replicatedStorage:WaitForChild("BenOVGUI") local gui = cgui:Clone() gui.Parent = playerGui gui.Enabled = true end end function UnloadGui() local BenOVGUI = playerGui:FindFirstChild("BenOVGUI") if BenOVGUI then BenOVGUI.Enabled = false end end tool.Equipped:connect(function(mouse) LoadGui() end) tool.Unequipped:connect(function() UnloadGui() end)
I've tested it out and had no problems, so it could really either be that your object directories are wrong or the gui is named differently.
If you mean when a tool is equipped, i think this will work :-) put this in a localscript in startergui and change line 2 to the gui you want to make visible and change BigSword to the tool name
game.Workspace:WaitForChild(game.Players.LocalPlayer.Name):WaitForChild("BigSword") --Change to tool name script.Parent.ScreenGui.TextLabel.Visible = true
Hope it works, if not tell me and ill try to fix it :)