how can I send a message from a local script in In-Experience Text Chat System (new chat system)
You can send a message from a local script in TextChatService using TextChatService.OnIncomingMessage!
Example:
Script in ServerScriptService
--<< Services >>--
local Players = game:GetService("Players")
--<< Variables >>--
local creatorId = game.CreatorId
--<< Add Attributes when player is added >>--
Players.PlayerAdded:Connect(function(player)
if player.UserId == creatorId and player:GetAttribute("isADeveloper") ~= true then
player:SetAttribute("isDeveloper", true)
end
end)
Local Script in StarterPlayerScripts
--<< Services >>--
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
--<< On Incoming Message Code >>--
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
local properties = Instance.new("TextChatMessageProperties")
if message.TextSource then
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
if player:GetAttribute("isDeveloper") == true then
properties.PrefixText = "<font color='#ADD8E6'>[DEV]</font> " .. message.PrefixText
end
end
return properties
end)
This should make a Chat Tag system once a player types and sends a message in the chat that has the isDeveloper
attribute.
If you’re looking for sending messages from local script to a server script, then you may want to use TextChatService.SendingMessage, TextChatService.MessageReceived, and TextChannel:SendAsync().
If you’re looking for TextChannel:DisplaySystemMessage(), then you can try it with a TextChatCommand. You want to have CreateDefaultTextChannels enabled in order to use this. As an example:
Go to TextChatService
and create a TextChatCommand
and set the PrimaryAlias
and SecondaryAlias
accordingly
Script in ServerScriptService
--!strict
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local Command: TextChatCommand = TextChatService:WaitForChild("TextChatCommand")
Command.Triggered:Connect(function(textSource, message)
local player = Players:GetPlayerByUserId(textSource.UserId)
if player then
local character = player.Character
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
for _, child in ipairs(humanoid:GetChildren()) do
if child:IsA("NumberValue") then
TweenService:Create(child, TweenInfo.new(), { Value = child.Value * 2}):Play()
end
end
end
end
end
end)
Local Script in StarterPlayerScripts
--!strict
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local Command: TextChatCommand = TextChatService:WaitForChild("TextChatCommand")
local SystemChannel: TextChannel = TextChatService:FindFirstChild("RBXSystem", true)
Command.Triggered:Connect(function(textSource, message)
SystemChannel:DisplaySystemMessage(string.format("Supersizing %s...", textSource.Name))
end)
More information about creating them can be found here.
Fun Fact: Both of the TextChatCommand examples are made by Roblox.
Hopefully this helps or make you have a better understanding about TextChatService and how it works and i hope the resources can help you as well!
Resources:
TextChatService
In-Experience Text Chat
In-Experience Text Chat System
Migrating from LegacyChatService to TextChatService
Attributes
ill look into that once I am back home