Infinite yield possible on 'TextChatService:WaitForChild("TextChannels")'

I don’t really know much about TextChatService, and when I tried this code out, it gave me the error: Infinite yield possible on ‘TextChatService:WaitForChild(“TextChannels”)’.

local function generateSystemMsg(MsgDict : array)
	return '<font color="#'..MsgDict["Color"]..'"><FontSize="'..MsgDict["FontSize"]..'"><Font face="'..MsgDict["Font"]..'">'..MsgDict["Text"]..'</font></font></font>'
end

local Choices = {
	"Make sure you join the group and like and favorite the game!";
	"Hi.";
	"If you see any exploiters or bugs/glitches, please report them!";
	"Sup."
}

while true do
	local randomTip = math.random(1, #Choices)
	local pickedTip = Choices[randomTip]
	
	local chat = game:GetService("TextChatService")
	local channel = chat:WaitForChild("TextChannels"):WaitForChild("RBXSystem")
	
	channel:DisplaySystemMessage(
		generateSystemMsg({
			Text = "[SYSTEM] "..tostring(pickedTip);
			Font = "Gotham";
			Color = Color3.fromRGB(255, 0, 0):ToHex();
			FontSize = "17";
		})
	)
	task.wait(1)
end

If you think you know what went wrong, pls let me know. Thank you in advance.

1 Like

My guess is you maybe put it in the wrong place? I added it to a LocalScript inside StarterPlayer/StarterPlayerScripts and I didn’t receive an error. Also you want to move the 2 lines where you set up chat and channel outside of your while loop. No need to keep getting those services and channels over and over.

1 Like

Infinite yield means that the script is :WaitForChild(“”) on something that doesnt exist . Check if the item you’re waiting for matches the name.

1 Like

The script is already located in StarterPlayerScripts, and when I moved those two lines like you said, I still got the error.

Yes moving the lines was only so that the code isn’t doing unnecessary calls over and over again. Have you tried to close studio and relaunch it?

1 Like

dont mind the error it just waits till the get the thing u pathed

1 Like

Oh something else you can check is to make sure you have the ChatVersion setting correct in the TextChatService in the explorer. If you have it set to LegacyChatSystem you will get this error.

Here is a correction for your function also:

local function generateSystemMsg(MsgDict : array)
	return '<font color="#'..MsgDict["Color"]..'" size="'..MsgDict["FontSize"]..'" face="'..MsgDict["Font"]..'">'..MsgDict["Text"]..'</font>'
end
1 Like

bro just dont care about it it just waits for the thing he pathed to WaitForChild(" ") it just gives a warn while waiting it

1 Like

You are mistaken. If you have LegacyChatSystem set it will never add the TextChatService items to the game when you are running…therefore you will NEVER be able to execute that code in the script.

2 Likes

I reset the ChatVersion and I no longer have the error, but now in the chat it prints the data.
image

And did you replace your function with the one I posted above?

1 Like

I just did that and it works! Thank you so much!

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