"Infinite Yield HumanoidRootPart" Error After Player Dies

You can write your topic however you want, but you need to answer these questions:
1. What do you want to achieve? Keep it simple and clear!
I want to make a bar height so it shows up the journey of the player while htey are climbing up.

  1. What is the issue? Include screenshots / videos if possible!
    Well, i made a script which references the HumanoidRootpart position (Y) into a local variable yHeight and it works perfectly… The issue comes after the player dies, it seems that the height bar clones himself at the top of the bar and also showing the error message “Infinite yield possible on 'Workspace.Edigamer_Roblox2:WaitForChild(“HumanoidRootPart”)” which i dont understand whats happening.

Location:
image

Script:

local bar = script.Parent

local heightTemplate = script:WaitForChild("PlayerHeight")


local goingUp = false


local maxHeight = workspace.HeightPart.Position.Y
local minHeight = 0

local heightDifference = maxHeight - minHeight


local increments = 1 / heightDifference



game:GetService("RunService").RenderStepped:Connect(function()
	
	
	
     for i, plr in pairs(game.Players:GetPlayers()) do
          
		local heightIndicator = heightTemplate:Clone()

		local plrImage = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		heightIndicator.PlayerImage.Image = plrImage

		heightIndicator.Parent = bar


		local char = plr.Character or plr.CharacterAdded:Wait()
			
		local yHeight = math.clamp(char:WaitForChild("HumanoidRootPart").Position.Y, minHeight, maxHeight)
			
		local yPos

		if goingUp then
			yPos = yHeight * increments

		else
			yPos = (maxHeight - yHeight) * increments
		end
		
		heightIndicator.Position = UDim2.new(heightIndicator.Position.X.Scale, heightIndicator.Position.X.Offset, yPos, 0)
          wait()
          heightIndicator:Destroy()
     end
end)
  1. What solutions have you tried so far?
    So basically i was trying to look if character was the problem and other things but i am still in the same thing.

Try:

local bar = script.Parent

local heightTemplate = script:WaitForChild("PlayerHeight")


local goingUp = false


local maxHeight = workspace.HeightPart.Position.Y
local minHeight = 0

local heightDifference = maxHeight - minHeight


local increments = 1 / heightDifference



game:GetService("RunService").RenderStepped:Connect(function()
	
	
	
     for i, plr in pairs(game.Players:GetPlayers()) do
          
		local heightIndicator = heightTemplate:Clone()

		local plrImage = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		heightIndicator.PlayerImage.Image = plrImage

		heightIndicator.Parent = bar


		local char = plr.Character or plr.CharacterAdded:Wait()
			
		local yHeight = math.clamp(char:WaitForChild("HumanoidRootPart", 10).Position.Y, minHeight, maxHeight)
			
		local yPos

		if goingUp then
			yPos = yHeight * increments

		else
			yPos = (maxHeight - yHeight) * increments
		end
		
		heightIndicator.Position = UDim2.new(heightIndicator.Position.X.Scale, heightIndicator.Position.X.Offset, yPos, 0)
          wait()
          heightIndicator:Destroy()
     end
end)
local bar = script.Parent

local heightTemplate = script:WaitForChild("PlayerHeight")


local goingUp = false


local maxHeight = workspace.HeightPart.Position.Y
local minHeight = 0

local heightDifference = maxHeight - minHeight


local increments = 1 / heightDifference



game:GetService("RunService").RenderStepped:Connect(function()
	
	
	
     for i, plr in pairs(game.Players:GetPlayers()) do
          
          if plr.Character.Humanoid.Health ~= 0 then
			local heightIndicator = heightTemplate:Clone()
	
			local plrImage = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
			heightIndicator.PlayerImage.Image = plrImage
	
			heightIndicator.Parent = bar
	
	
			local char = plr.Character or plr.CharacterAdded:Wait()
				
			local yHeight = math.clamp(char:WaitForChild("HumanoidRootPart").Position.Y, minHeight, maxHeight)
				
			local yPos
	
			if goingUp then
				yPos = yHeight * increments
	
			else
				yPos = (maxHeight - yHeight) * increments
			end
			
			heightIndicator.Position = UDim2.new(heightIndicator.Position.X.Scale, heightIndicator.Position.X.Offset, yPos, 0)
	          wait()
	          heightIndicator:Destroy()
          end
     end
end)

Ah yes, i have tried that metod adding a TimeOut to wait for the HRPart, but after testing the game, the error is still showing.

still getting the same error, also i havent though about trying the statement if when the health is zero thank you for trying.

Did you make sure that ResetOnSpawn for the Screengui was checked?

Remove the WaitForChild part, the script already wait before the creation of the chr.

Yes i did when i started doing the height bar.

Ah when they die the character get’s destroyed so make it asking if there is a character and if the characters health is greater than 0

You should probably also add a check for the HumanoidRootPart.

... -first half of the script

local HumanoidRootPart = Char:FindFirstChild("HumanoidRootPart")
if not HumanoidRootPart then return end

... -rest of the script

You mean the WaitForChild for character or HumanoidRootPart?
Also still getting the same error despite doing what you propose

Try this solution script, if it works the character root part has not name as HumanoidRootPart but another:

local bar = script.Parent

local heightTemplate = script:WaitForChild("PlayerHeight")


local goingUp = false


local maxHeight = workspace.HeightPart.Position.Y
local minHeight = 0

local heightDifference = maxHeight - minHeight


local increments = 1 / heightDifference



game:GetService("RunService").RenderStepped:Connect(function()



	for i, plr in pairs(game.Players:GetPlayers()) do

		local heightIndicator = heightTemplate:Clone()

		local plrImage = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		heightIndicator.PlayerImage.Image = plrImage

		heightIndicator.Parent = bar
		

		local char = plr.Character or plr.CharacterAdded:Wait()
		
		local hrp = plr:FindFirstChildOfClass("Humanoid").RootPart

		local yHeight = math.clamp(hrp.Position.Y, minHeight, maxHeight)

		local yPos

		if goingUp then
			yPos = yHeight * increments

		else
			yPos = (maxHeight - yHeight) * increments
		end

		heightIndicator.Position = UDim2.new(heightIndicator.Position.X.Scale, heightIndicator.Position.X.Offset, yPos, 0)
		wait()
		heightIndicator:Destroy()
	end
end)

I just tested it right now and the output showed more errors about indexing nil with the position of HRPart after i corrected the line where you put:

local hrp = plr:FindFirstChildOfClass("Humanoid").RootPart

because is indexing with nil and also i dont think using FindFirstChildOfClass would be a best way to earn the hrp and writting .RootPart after the “Humanoid” sentence.
In short words is not working.

I made that way but it really gets me out of why didnt work too

Iproved it before the fares method and still not working

Also i want to show a videoclip of the issue because this error:
robloxapp-20230409-2014414.wmv

Can you test it modified script:

local bar = script.Parent

local heightTemplate = script:WaitForChild("PlayerHeight")


local goingUp = false


local maxHeight = workspace.HeightPart.Position.Y
local minHeight = 0

local heightDifference = maxHeight - minHeight


local increments = 1 / heightDifference

local lastTime = DateTime.now()
local countdown = 100
game:GetService("RunService").RenderStepped:Connect(function()
	repeat wait() until DateTime.now().UnixTimestampMillis-lastTime>countdown --Countdown System
	lastTime = DateTime.now()
	
	for i, plr in pairs(game.Players:GetPlayers()) do
		
		local heightIndicator = heightTemplate:Clone()

		local plrImage = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		heightIndicator.PlayerImage.Image = plrImage

		heightIndicator.Parent = bar
		

		local char = plr.Character or plr.CharacterAdded:Wait()
		
		local hrp = char:FindFirstChild("HumanoidRootPart")
		if not hrp then continue end

		local yHeight = math.clamp(hrp.Position.Y, minHeight, maxHeight)

		local yPos

		if goingUp then
			yPos = yHeight * increments

		else
			yPos = (maxHeight - yHeight) * increments
		end

		heightIndicator.Position = UDim2.new(heightIndicator.Position.X.Scale, heightIndicator.Position.X.Offset, yPos, 0)
		wait()
		heightIndicator:Destroy()
	end
end)