I was wondereing how I could make a message be sent in the chat. Here is my current script but it doesn’t work:
local success, errormsg = pcall(function()
game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", { Text = "[SYSTEM] Hello World", Color = Color3.fromRGB( 255,0,0 ), Font = Enum.Font.Arial, FontSize = Enum.FontSize.Size24 } )
end)
if errormsg then
warn(errormsg)
end
Thanks for the help but it still doesn’t work. Here is the updated script:
local function getSystemMsg(MsgDict: array)
return '<font color="#'..MsgDict["Color"]..'"><font size="'..MsgDict["FontSize"]..'"><font face="'..MsgDict["Font"]..'">'..MsgDict["Text"]..'</font><font></font>'
end
local channel = ChatService:WaitForChild("RBXSystem")
print(channel)
channel:DisplaySystemMessage(
getSystemMsg({
Text = "THIS IS A TEST";
Font = "Gotham";
Color = Color3.fromRGB(255,0,0):ToHex();
FontSize = "17";
}
)
)
As it turns out, the channels may not be fully loaded by the time message is sent.
-- Simplified version
local TextChatService = game:GetService("TextChatService")
local SystemChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXSystem")
SystemChannel.MessageReceived:Connect(function(message)
print(message) --> prints the instance
end)
task.wait(1)
local sentMsg = SystemChannel:DisplaySystemMessage("Hello, World!")
print(sentMsg) --> prints the instance
For testing purposes, task.wait(1) before calling :DisplaySystemMessage() worked, although I don’t like “magic numbers” and yielding with wait() to fix the code. When I can, I’ll do some more research to find a better solution than yielding with a guess.
I could try that but it’s not being called straight away. I have just showed the part that handles the message. I get an error in the console: Infinite yield possible on 'TextChatService:WaitForChild("RBXSystem")'
This script is in StarterGui because it also handles UI
I have resolved the issue! I was doing ChatService:WaitForChild("RBXSystem") instead of ChatService:WaitForChild(“TextChannels”):WaitForChild(“RBXSystem”)
This function works once the GUIs are loaded, which means it can’t work right away in StarterPlayerScripts. The GUIs first need to be replicated into player.PlayerGui.
Check the code again, there’s :WaitForChild("TextChannels") missing.