local SG = game:GetService("StarterGui")
local function chat(message:string, color:Color3)
SG:SetCore("ChatMakeSystemMessage", {Text = message, Colour = color})
end
chat("test", Color3.new(1, 0, 1))
It should send “test” in the chat, though it does nothing for some reason.
local SG = game:GetService("StarterGui")
local function chat(message:string, color:Color3)
SG:SetCore("ChatMakeSystemMessage", {Text = message, Color = color})
end
chat("test", Color3.new(1, 0, 1))
You can make one with Instance.new but there should be some default channels that are parented under TextChatService when your game starts. (Assuming the TextChatService.CreateDefaultChannels is true which it is by default)
The path is game:GetService("TextChatService").TextChannels
Gotcha, if you wish to have that option disabled, that means we will trust you to create TextChannels and add users to them manually.
To create a TextChannel, you can use the Insert Menu in studio to parent your TextChannel under TextChatService. Or you can use Instance.new(“TextChannel”) at runtime instead.
You’ll wanna make sure you also call TextChannel:AddUserAsync(userId) for each player in your game that is expected to see that channel.
For the record though, does this mean you do have TextChatService enabled? The chat window is dark black?
Oh well, I have TextChatService enabled, though I can’t send messages. But I guess this will be fixed when I add the player to TextChannel that I will create. I will go and try.
Sure, give it a shot. There’s a bit of boilerplate code that you’ll have to write to add the users to the TextChannel when they join the game (assuming you want everyone to join your channels when they join the game which is pretty standard)
In a server script, you can write:
-- server script
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local myCoolTextChannel = TextChatService:FindFirstChild("myCoolTextChannel") -- this can be named whatever, assuming this is an actual TextChannel object
assert(myCoolTextChannel and myCoolTextChannel:IsA("TextChannel"), "custom chat channel is missing!")
-- this will unconditionally add every user that joins the game to the custom channel
Players.PlayerAdded:Connect(function(player)
myCoolTextChannel:AddUserAsync(player.UserId)
end)
In a client script, you can then use DisplaySystemMessage with that TextChannel when gameplay stuff happens
--client script
-- ...
local playerMoneyChangedBindableEvent = ReplicatedStorage.playerMoneyChangedBindableEvent
playerMoneyChangedBindableEvent.Event:Connect(function(player, newMoneyAmount)
myCoolTextChannel:DisplaySystemMessage(`{player.DisplayName} has acquired more wealth (${newMoneyAmount})`)
end)
--server
local TCS = game:GetService("TextChatService")
local Players = game:GetService("Players")
local channel = Instance.new("TextChannel")
channel.Name = "PlayersChannel"
channel.Parent = TCS
local RS = game:GetService("ReplicatedStorage")
local remotes = RS:WaitForChild("RemoteEvents")
local event = remotes:WaitForChild("ServerMessage")
local function onPlayerAdded(plr:Player)
channel:AddUserAsync(plr.UserId)
event:FireClient(plr)
end
Players.PlayerAdded:Connect(onPlayerAdded)
for _, plr:Player in ipairs(Players:GetChildren()) do --incase player loads before the script
onPlayerAdded(plr)
end
--client
local RS = game:GetService("ReplicatedStorage")
local remotes = RS:WaitForChild("RemoteEvents")
local event = remotes:WaitForChild("ServerMessage")
local TCS = game:GetService("TextChatService")
local channel:TextChannel = TCS:WaitForChild("PlayersChannel")
local function chat()
print("test message")
channel:DisplaySystemMessage("test")
end
event.OnClientEvent:Connect(chat)
It prints the test message, but doesn’t display anything in chat. And players still can’t chat.
Wait, it suddenly started to show the message. Though I still have the same issue - players can’t chat.
Ah I see the issue here. You’re firing the chat message before the chat window has loaded. This is an edge case we can likely address by filling a queue of messages to be processed before the chat window has been loaded.
If you were to add a task.wait(1) before :FireClient for example, you’ll see the message appear.
Since you are not using the default channels, you’ll have to tell the ChatInputBar which channel you expect users to write to at any given time (since you can have many channels)
Try setting ChatInputBarConfiguration.TargetTextChannel to PlayersChannel in edit mode or at runtime. The default UI reads this value to determine where to send user input to.
Yup, you can use TextChannel.OnIncomingMessage to format the messages and names however you need to. Here’s a pretty quick overview on how you can implement that on the wiki: In-Experience Text Chat | Roblox Creator Documentation
The “Coloring Usernames” example there might be relevant to you right now.
The default channels have their own TextChannel.OnIncomingMessage callbacks defined by default (which you can override if you dont like stuff like name colors I guess) which is why most people dont really need to bother with the formatting but in your case you have full control in how these messages can be displayed.