Infinite yield possible on WaitForChild()

Heya, im making a healthbar and i get this warning/error message.

Infinite yield possible on WaitForChild()

Here is the code(this is not all of it, its too big)

	if plr:FindFirstChild("Badge") then
		stats.RobotName.TextColor3 = plr.Badge.BadgeColor.Value
	end
	if plr:FindFirstChild("_nickname") == nil then
		stats.RobotName.Text = plr.Name
	else
		stats.RobotName.Text = plr["_nickname"].Value
		stats.RobotName.TextColor3 = Color3.new(1,1,1)
	end
	stats.HP.Text.Text = "HP "..char.Humanoid.Health.."/"..char.Humanoid.MaxHealth
	stats.HP.Bar.Size = UDim2.new(char.Humanoid.Health/char.Humanoid.MaxHealth,0,1,0)
	stats.PlayerToHideFrom = plr
	stats.Parent = char.Head
    local function Yes()
			if stats:FindFirstChild("HP") and char:FindFirstChild("Humanoid") then
			stats.HP.Text.Text = "HP "..char.Humanoid.Health.."/"..char.Humanoid.MaxHealth
			stats.HP.Bar.Size = UDim2.new(char.Humanoid.Health/char.Humanoid.MaxHealth,0,1,0)
			end
		if char:FindFirstChild("KR") then
		if char.KR.Value > 0 then
			stats.HP.Text.TextColor3 = Color3.new(1,0,1)
		else
			stats.HP.Text.TextColor3 = Color3.new(1,1,1)
		end
		stats.HP.Bar.KR.Size = UDim2.new(char.KR.Value/char.Humanoid.Health,0,1,0)
		stats.HP.Bar.KR.Position = UDim2.new(1-char.KR.Value/char.Humanoid.Health,0,0,0)
	else
		stats:WaitForChild('HP').Text.TextColor3 = Color3.new(1,1,1)--This is were the error message happened
	end
    end
    char.Humanoid.Changed:Connect(Yes)
    char:WaitForChild("KR").Changed:Connect(Yes)
		if plr.LOVE.Value < 20 then
			plr.Character.Humanoid.MaxHealth = (20 + (4*(plr.LOVE.Value-1))) + SelectedArmor.Value.HPBonus.Value
			plr.Character.Humanoid.Health = (20 + (4*(plr.LOVE.Value-1))) + SelectedArmor.Value.HPBonus.Value
		elseif plr.LOVE.Value >= 20 then
			plr.Character.Humanoid.MaxHealth = (100 + (5*(plr.LOVE.Value-20))) + SelectedArmor.Value.HPBonus.Value
			plr.Character.Humanoid.Health = (100 + (5*(plr.LOVE.Value-20))) + SelectedArmor.Value.HPBonus.Value
		end
1 Like

This warning means that wait for child is waiting for HP, but it is not found. Are you sure that “HP” is a child of stats?

Try changing that line to referencing HP using the . method, as you did earlier.

stats.HP.Text.TextColor3 = Color3.new(1,1,1)

If this doesn’t work, can you explain exactly what “stats” is? Is it an Instance, or a Table?

1 Like

This info message appears, occasionally. If you’d like to avoid it just do

WaitForChild("", math.huge)
3 Likes

Or just replace math.huge with whatever number of seconds you want to yield before continuing to run the rest of the code