For some reason, whenever I put the GUI into StarterGUI so I can edit it, and then bring the GUI back into the tool, the script doesn’t think it’s there and I get HUD is not a valid member of Tool "Workspace.ArtOfVH3.DWhiteTShirt in the output as an error. The same happens when I use a different copy of the same GUI. Help?
local gui
local equipped = false
script.Parent.Equipped:Connect(function()
equipped = true
if not game.Players.LocalPlayer.PlayerGui:FindFirstChild("HUD") then -- Gui's name.
gui = script.Parent.HUD:Clone() -- Replace with GUI's name.
gui.Parent = game.Players.LocalPlayer.PlayerGui
end
end)
script.Parent.Unequipped:Connect(function()
equipped = false
gui:Destroy()
end)
You can clone the gui from replicated storage or something to the player whenever he equips that tool, and when he unequips, remove it from player.PlayerGui.
[if you’re using remotes, make sure to remove his gui from the server - if the server found the gui in the playe]r
local gui = script.Parent.HUD
local clone = nil
local equipped = false
script.Parent.Equipped:Connect(function()
if not equipped then
equipped = true
clone = gui:Clone() -- Replace with GUI's name.
clone.Parent = game.Players.LocalPlayer.PlayerGui
end
end)
script.Parent.Unequipped:Connect(function()
equipped = false
if clone then
clone:Destroy()
end
end)