Low health text has an issue

so when i have less than 30 health or 30 the text appears like a warning for low health, and when i increase the health more than 30 the text still appears, there is no errors nor warnings
here script:

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:FindFirstChildOfClass("Humanoid")

hum.HealthChanged:Connect(function(hlth)
    if hlth <= 30 then
        while wait() do
            script.Parent.Visible = true
            wait(0.5)
            script.Parent.Visible = false
            wait(0.5)
        end
    else
        script.Parent.Visible = false
    end
end)
3 Likes

In your code, once the ‘while’ loop starts it goes on forever and never stops

4 Likes

There is definitely a better way to achieve the effect you’re going for, but if you just want to fix the issue, try this:

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:FindFirstChildOfClass("Humanoid")

hum.HealthChanged:Connect(function(hlth)
    if hlth <= 30 then
        while wait() do
            script.Parent.Visible = true
            wait(0.5)
            script.Parent.Visible = false
            wait(0.5)
            
            if hum.Health > 30 then
                script.parent.Visible = true
                break
            end

        end
    else
        script.Parent.Visible = false
    end
end)
3 Likes

i have fixed it and it works
10

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.