TextChatService TextChannels aren't fully loaded when waited for

i have the following code which breaks completely if I remove the task.wait(1):


local ReplicatedStorage = game:GetService("ReplicatedStorage")

local TextChatService = game:GetService("TextChatService")


local SendPlayerSystemMessageEvent = ReplicatedStorage:WaitForChild("SendPlayerSystemMessage")


local SystemChatChannel : TextChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXSystem")



SendPlayerSystemMessageEvent.OnClientEvent:Connect(function(...)


	task.wait(1)

	local text = ""

	local messages = { ... }	

	local messageCount = #messages

	for i, message in ipairs(messages) do

		text = text .. message .. (i + 1 <= messageCount and "\n" or "")
	end
	
	SystemChatChannel:DisplaySystemMessage(text)
end)

How can I verify these TextChannels are fully loaded if WaitForChild is not sufficient?

I should also mention that using

while not SystemChatChannel do task.wait(1) end

was not a solution (that also makes it break)

I found the solution. You have to wait for one of the Core scrpts to load. I don’t know exactly which one, but waiting for the ChatMakeSystemMessage works for me and seems most appropriate for my use-case.

I did it by making this function:

local function requireSetCore(FunctionName, configTable, dur)

	local s = nil
	
	while not s do 
        
        s = pcall(StarterGui.SetCore, StarterGui, FunctionName, configTable) 
     
        task.wait(dur) 
    end 
end

and replacing the task.wait(1) with this:

requireSetCore("ChatMakeSystemMessage", { Text = "" }, 0)
1 Like