Infinite yield finding UI element

For some reason my script isn’t finding a textlabel ‘TaggedName’ inside of my NameDisplay frame and I don’t know why that is. Please help.

  1. What is the issue? Include screenshots / videos if possible!

This is how my UI hierarchy looks like. I double checked again and again, it all looks fine to me. I dont know why the script isn’t finding the textlabel:
image

-- UI References with WaitForChild
local TaggedPlayerUI = script.Parent
local canvas = TaggedPlayerUI:WaitForChild("Canvas")
local holderFrame = canvas:WaitForChild("HolderFrame")
local nameDisplay = holderFrame:WaitForChild("NameDisplay")
local taggedName = nameDisplay:WaitForChild("TaggedName")

Any help would be appreciated greatly, thanks!

Looks like it should be fine to me. What is line 14 of the script? Is that the local taggedName = nameDisplay:WaitForChild("Taggedname")?

1 Like

I recreated your setup and got the same error.

I remember having this issue a long time ago when defining a bunch of variables like you have.

That is when I switched to using ObjectValue as often as possible.

With an ObjectValue you do not need to type the path.

HERE HOW:

Insert an ObjectValue inside your script:

With the ObjectValue highlighted, look in your Properties window for Value. Click on Value and you should see a red X.

Screen Shot 2024-12-20 at 4.30.07 PM

Now, in your Explorer window, click on the Instance you want to store inside the ObjectValue:

Screen Shot 2024-12-20 at 4.31.31 PM

Look back at the Properties panel. You can see that TaggedName is now stored as the value.

Screen Shot 2024-12-20 at 4.32.29 PM

You can now type a single line of code to access the value:

local taggedName = script:WaitForChild("TaggedName").Value

Make sure to add the .Value at the end since you are wanting the Value stored in the ObjectValue.

Congrats! You just shortened your code by 4 lines and prevented a headache.

NOTE: This works everywhere except if your try and link Instances from different ScreenGuis since they are cloned into PlayerGui) It does work, however within the same ScreenGui as you have it now.

1 Like

Maybe try removing the WaitForChilds since GUIs load everything at once, I think?

Yeah that’s right, that’s line 14 that’s giving the error somehow

Ok ill try that and tell you how that turns out

I recreated the setup like oof did and also got the error a few times. I mucked around with it and the error stopped showing. I thought maybe it was a hidden character in the text or something but pasting your code from the comment doesn’t generate the error anymore even in a new file.

Based what oof found it doesn’t seem like your problem is something you did. There is a timeout parameter in the WaitForChild(thing_to_find, timeout) that you can play around with to see if it resolves for you without error, or just use the ObjectValue idea. Seems to maybe be a processing time related thing.

To be honest, I don’t think you even need to be using WaitForChild in this case. Although that doesn’t explain the error.

If you use FindFirstChild instead of WaitForChild, does it solve the issue entirely or does it give an “Attempt to index nil” sort of error (error relating to having the value being nil)

Hit the play button, navigate to
Players.(you).PlayerGui.TaggedPlayerTracker.Canvas.HolderFrame.NameDisplay.TaggedName
In the explorer

If you are going to start using ObjectValues in your game, then create this script on ServerScriptService:




--===========================
-- VALIDATE ALL OBJECTVALUES
--===========================

task.wait(4)

local function ValidateObjectValues(Service)
	for _, item in pairs(Service:GetDescendants()) do
		if item and item:IsA("ObjectValue") then
			local success,error = pcall(function()
				local part = item.Value.Parent -- if no parent then instance is probably deleted
			end)
			if success then
				-- do nothing
			else
				if item.Parent.Name ~= “EmptyObject" then
					print("VALIDATE OBJECT VALUES | FAIL", Service, item.Parent, item.Name) -- change depth of parent as needed
				end
			end
		end
	end
end

print("VALIDATE OBJECT VALUES | Start")

local function SendServices()
	ValidateObjectValues(game.Workspace) task.wait()
	ValidateObjectValues(game.ReplicatedStorage) task.wait()
	ValidateObjectValues(game.ServerScriptService) task.wait()
	ValidateObjectValues(game.ServerStorage) task.wait()
	ValidateObjectValues(game.StarterGui) task.wait()
	ValidateObjectValues(game.StarterPack) task.wait()
	ValidateObjectValues(game.StarterPlayer) task.wait()
	ValidateObjectValues(game.SoundService) task.wait()
end
SendServices()

print("VALIDATE OBJECT VALUES | Stop")

If you create an ObjectValue, then delete the Instance that is stored inside the Value, the Value will be empty but the “Name” of the Instance still shows in the Value field.

This script will identify any empty ObjectValues.

You can Enable it whenever you want to check.

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