I’m trying to fix a bug where a billboard Gui duplicates itself in a spot on the baseplate after death.
Here’s the LocalScript that I used to try to fix this issue and be a solution.
Code Inside of The Script:
local health = script.Parent.Parent.Parent.Humanoid.Health
if health < 1 then
script.Parent.Visible = false
end
-- Don't mind my horrible scripting please.
if health < 1 then
script.Parent.Visible = false
end
This will only run once, and unless the NPC is already dead upon the LocalScipt being loaded, it will read that the health of the NPC is above 1 and finishes; nothing else will happen from that point. Instead, you would want to be constantly listening for the NPC’s health. This can be done with the following:
Condition-controlled loop, also known as a while loop
.Changed event
:GetPropertyChangedSignal()
.Died event
Since you’re dealing with an NPC, the .Died event would be what you would want to use in this situation (assuming the NPC has a Humanoid object), just like how @Unknown91248 has mentioned. The .Died event fires after the Humanoid, well, dies, which is perfect for your situation as you want the Billboard to disappear after the NPC dies.