Gui disappear script not working

I have this script because I want the gui above an NPCs head to disappear on death. But its not working,
any solutions?

if script.Parent.Parent.Humanoid.Health <= 0
	then
		script.Parent:Destroy()
	end

try a better way:

script.Parent.Parent.Humanoid.Died:Connect(function()
	script:Destroy()
end

I already tried that but it didn’t work.

Can you show us a screenshot of the explorer? showing the parents and descendants of the script ?

script.Parent.Parent.Humanoid.Died:Connect(function()
	if script.Parent.Enabled == true then
		script.Parent.Enabled = not script.Parent.Enabled
	end
end

You should try this one

It doesn’t work. Any other ideas?

Are you looking after errors and warnings in the output ?

Where is the NPC located? If workspace then localscripts dont work in workspace.

Yes, but there isn’t any errors or anything.

The NPC is located in a model in the workspace and the script is located in a gui in the NPC. I also tried all the solutions with a normal script but it still didn’t work.

How do you check if the script is running?

The nations script has to be a normal script not a local script. Local scripts dont function in workspace. After you changed it, try this code:

local NPChum = game.Workspace.NPC1:FindFirstChild("Humanoid")

if NPChum and NPChum.Health >= 0 then 

game.Workspace.NationsFlag:Destroy()

No the script isn’t not running.

A comment on this though: they do run if they are in the player’s character. Provided the condition for LocalScripts running in characters is that they must be immediate children and not decendants, this would still be a valid setup.

Seems with the above comment, that confirms that LocalScripts must be immediate children of the character for the execution to be valid.

1 Like

That didn’t work. Any other ideas?

local HUM = game.Workspace.NPC1:FindFirstChild("Humanoid")
if HUM then
	HUM.Died:Connect(function()
		local GUI = HUM.Parent:FindFirstChild("NationsFlag")
		if GUI and GUI.Enabled then
			GUI.Enabled == false
		end
	end)
end

This will work, since Characters have localscripts in them it might work. I ain’t one of the best programmers but maybe this should help.

This thread is turning into a mess, so let’s try to set this straight

Put a Script (not a local script!!!) directly under the character. Name it whatever you want for clarity. In the script, paste this in (AND READ THE NEXT BIT SO YOU UNDERSTAND WHAT IT DOES)

local FlagGui = script.Parent:WaitForChild("NationsFlag")
local Humanoid = script.Parent:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
	FlagGui.Enabled = false
end)

First the script waits for the humanoid to load. Then it does the same for the flag. It then connects a function to the event Humanoid.Died, to disable the flag when the humanoid ‘dies’.

1 Like

Please, please read this thread. You’ll thank me and Kampfkarren later.

This didn’t work. Any other ideas?

No this didn’t work either. Any other ideas?