How does Chat service work and what can I do with it?

How does Chat service work and what can I do with it?

Here are a few examples:

local ServerScriptService = game:GetService("ServerScriptService")

--path of the service
local ChatService = require(ServerScriptService.ChatServiceRunner.ChatService)

--chat bot
local Bot = ChatService:AddSpeaker("botName") --create a speaker object
Bot:SetExtraData("NameColor", Color3.fromRGB(100, 100, 255)) --change their name color
--add a tag to their name(with the given properties)
Bot:SetExtraData("Tags", {{TagText = "System", TagColor = Color3.fromRGB(150, 150, 150)}}) 
repeat task.wait() until ChatService:GetChannel("all") --wait for the main channel to load
Bot:JoinChannel("all") --add our bot to the main channel
Bot:SayMessage("hi!", "all") --send a message to the main channel

--listen to chat speakers being added(basically users)
ChatService.SpeakerAdded:Connect(function(name) 
	--grab the speaker object
	local Speaker = ChatService:GetSpeaker(name)

	--change user chat name color:
	Speaker:SetExtraData("NameColor", Color3.fromRGB(200, 0, 0))
	--change user messages color:
	Speaker:SetExtraData("ChatColor", Color3.fromRGB(255, 255, 0))
	
	--an array containing our tags {tag1, tag2, tag3, etc.}
	--each tag is a table of properties describing it
	local Tags = {
		{TagText = "tag", TagColor = Color3.fromRGB(100, 100, 255)},
		{TagText = "tag2", TagColor = Color3.fromRGB(100, 255, 100)}
	}
	--apply tags to user
	Speaker:SetExtraData("Tags", Tags)
end)
3 Likes

Can you put Comments on a lot of parts on the code? you can’t just give someone the food that they need to cook without telling them the recipe!

3 Likes