Infinite faces and not disappearing

local character = script.Parent
local head = character:FindFirstChild(“Head”)
local face = head:FindFirstChild(“face”)

local humanoid = character:FindFirstChild(“Humanoid”)
local animation = game.ReplicatedStorage:FindFirstChild(“LowHealthAnim”)
local loadedAnimation = humanoid:LoadAnimation(animation)

while wait() do
if humanoid.Health <= 40 then
loadedAnimation:Play()

    face:Destroy()

    local newFace = Instance.new("Decal", head)
    newFace.Texture = "rbxassetid://434152481" 

else
    loadedAnimation:Stop()

end

end*

So i have this script that shoud play a anim and remove your face and put other everything works fine but we get an infinite number of faces and after your health is higher they don’t disappear.

Maybe make a debounce when the health is lower or equal than 40 then debounce = true and when its more than 40 then if debounce == true then debounce = false ? (and you forget to put all your script with ```lua)

3 notes:

1.Do not put the parent of any instance as an argument, it affects performance. There is a forum post on it.

2.Do you want to check your condition each time the player’s hp changes? if so, instead of a loop, use HealthChanged.

3.You might need to use a debounce.

Instead of instancing a new decal why don’t you just use the current one and change its texture accordingly?

1 Like

thanks that works but do u have any idea how to save the original id of the face

Yeah, declare a variable for it and if it isn’t assigned then assign it.

--top of script
local faceId --placeholder for later

--later in script
if not faceId then faceId = value end --if value not assigned then assign a value