GUI on equip script being finnicky

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

I’m pretty sure GUI Objects destroy when they’re parented to tools. Try putting the GUI in ReplicatedStorage and modifying your script accordingly.

the tools are inside of folders inside of replicatedstorage

That doesn’t matter, the GUI is still inside of a tool.

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

1 Like

Try this?

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)