How to make this GUI disappear?

I got this bandage that heals 3 times and then destroys itself. The problem is the fact that I can’t seem to make the HUD disappear before the tool destroys, so the HUD stays. I’ve tried making it not visible, transparency to 1, nothing. I don’t know how to proceed, so I need some help.

if it helps this is the code that clones the GUI and puts it into the player’s screen

local gui

local equipped = false

script.Parent.Equipped:Connect(function()
	equipped = true
	if not game.Players.LocalPlayer.PlayerGui:FindFirstChild("HUD") then -- Gui's name.
		script.Parent.HUD.Enabled = true
		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

You’re creating or presenting 2 Guis at the same time. Maybe just clone once and put it in a variable, refer that variable to manipulate its properties.

1 Like
local gui = script.Parent.HUD:Clone()
local tool = script.Parent

local equipped = false

tool.Equipped:Connect(function()
    equipped = true
    script.Parent.HUD.Enabled = true
    gui.Parent = game.Players.LocalPlayer.PlayerGui
end)

tool.Unequipped:Connect(function()
	equipped = false
	gui:Destroy()
end)
1 Like

I can set the visible property with that script, but for the healing script (doubling as the durability script) I doesn’t seem to work. Maybe its the code where I think it tries to detect and find the HUD in the player’s gui?

You can set the GUI visible, once you’re done set it invisible.

1 Like

This is my code for the durability and deleting it, but it doesn’t seem to be doing anything

	if Durability == 1 then --- destroy after durability runs out
		
		print("Tool broke")
		
		
		script.Parent.HUD.Enabled = false
		
		wait(0.5)
		script.Parent:Destroy() --- actual destroy self line
	end
	end
1 Like

Does the print statement works?

yeah, but the HUD is still visible after the tool is destroyed

1 Like

You could try destroying the Gui when you break the tool. If that doesn’t work, you can go to the player’s PlayerGui and find the GUI and delete it from there.

How would I do the first part if the tool (and therefore the script) doesn’t exist anymore?

edit: I’ve tried the second part with

game.Players.LocalPlayer.PlayerGui.HUD:Destroy()

but it doesn’t seem to do anything

1 Like

Could you show us a video of everything you’ve explained including the Explorer window?

Yeah sure, here: Devforum Help thing - YouTube

1 Like

you’re using LocalPlayer in a script, so its checking for a player named LocalPlayer

assuming your script is in a tool located inside the players backpack you can do script.Parent.Parent.Parent to get the players instance

Try replacing this with gui.Enabled = true

1 Like

the tool is located inside of my class system inside startergui, so it won’t work. If I add enough .Parent’s, its just the same as game.Players.PlayerGui

look at the output,


it cant find playergui and destroy the gui because you put localplayer in a script

1 Like

well I have to get the PlayerGui, but I don’t know how to make it link to the player, so I looked through it and thought LocalPlayer must be it. I can’t get the PlayerGui if there is nothing in front of Players

you can use localplayer only in a localscript
to fix your problem add this
local Player = script.Parent.Parent.Parent
then replace every LocalPlayer with Player

2 Likes