Button chat message TextChatService

Hello, Iā€™m trying to change the script to TextChatService. Right now, it only works with legacy chat.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Function to handle button click
local function onButtonClick()
	local message = "Welcome šŸ‘‹" -- The message you want to send
	local player = Players.LocalPlayer -- Get the local player
	if player then
		ReplicatedStorage:WaitForChild("DefaultChatSystemChatEvents"):WaitForChild("SayMessageRequest"):FireServer(message, "All") -- Send message to all players
	else
		print("Local player not found!") -- If local player not found, print a message to the output
	end
end

-- Connect the button click event to the function
-- Replace "TextButton" with the actual name of your TextButton
script.Parent.Activated:Connect(onButtonClick)

Thank you!

I posted about this a while ago with a similar issue which was solved here:

A solution using your code would be:

local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")

local function onButtonClick()
    local message = "Welcome šŸ‘‹"
    local channel = TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXGeneral")
    channel:SendAsync(message)
end

script.Parent.Activated:Connect(onButtonClick)

Note that the solution above (channel:SendAsync()) only works in LocalScripts.

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