Học
Lớp công cụ
TextChatService
Không Thể Tạo
Dịch Vụ

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.


Tóm Tắt
Phương Pháp
CanUsersChatAsync(userIdFrom: User,userIdTo: User):boolean
CanUsersDirectChatAsync(requesterUserId: User,userIds: {any}):{any}
DisplayBubble(partOrCharacter: Instance,message: string):()
GetChatGroupsAsync(players: Instances):{any}
Thành viên kế thừa

Tài Liệu Tham Khảo API
Thuộc Tính
ChatTranslationEnabled
Không Sao Chép
Bảo Mật Kịch Bản Roblox
Đọc Song Song
Các khả năng: Chat
TextChatService.ChatTranslationEnabled:boolean

ChatVersion
Đã Lỗi Thời

CreateDefaultCommands
Bảo Mật Plugin
Đọc Song Song
Các khả năng: Chat
TextChatService.CreateDefaultCommands:boolean

CreateDefaultTextChannels
Bảo Mật Plugin
Đọc Song Song
Các khả năng: Chat
TextChatService.CreateDefaultTextChannels:boolean

Phương Pháp
CanUserChatAsync
Sinh Lợi
Các khả năng: Chat
TextChatService:CanUserChatAsync(userId:User):boolean
Tham Số
userId:User
Lợi Nhuận

CanUsersChatAsync
Sinh Lợi
Các khả năng: Chat
TextChatService:CanUsersChatAsync(
userIdFrom:User, userIdTo:User
Tham Số
userIdFrom:User
userIdTo:User
Lợi Nhuận

CanUsersDirectChatAsync
Sinh Lợi
Các khả năng: Chat
TextChatService:CanUsersDirectChatAsync(
requesterUserId:User, userIds:{any}
Tham Số
requesterUserId:User
userIds:{any}
Lợi Nhuận
Mẫu mã
CanUsersDirectChatAsync
local TextChatService = game:GetService("TextChatService")
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- Kiểm tra các người tham gia đủ điều kiện
if #directChatParticipants > 0 then
local directChannel = Instance.new("TextChannel")
directChannel.Parent = TextChatService
for _, participant in directChatParticipants do
directChannel:AddUserAsync(participant)
end
return directChannel
end
warn("Không thể tạo TextChannel. Không đủ người dùng đủ điều kiện.")
return nil

DisplayBubble
Các khả năng: Chat
TextChatService:DisplayBubble(
partOrCharacter:Instance, message:string
):()
Tham Số
partOrCharacter:Instance
message:string
Lợi Nhuận
()

GetChatGroupsAsync
Sinh Lợi
Các khả năng: Chat
TextChatService:GetChatGroupsAsync(players:Instances):{any}
Tham Số
players:Instances
Lợi Nhuận
Mẫu mã
Di Chuyển Người Chơi Đến Máy Chủ Trò Chuyện Tốt Nhất
-- Kịch bản máy chủ
local TextChatService = game:GetService("TextChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- ID địa điểm đích
--[[
Trạng thái máy chủ toàn vũ trụ đã được stub.
Trên thực tế, dữ liệu này có thể được lưu trữ và cập nhật bằng cách sử dụng MemoryStore
hoặc một hệ thống backend khác.
Hình dạng ví dụ:
ActiveServers = {
{
serverId = "abc",
accessCode = "reserved-server-code",
groupUserCounts = {
groupA = 12,
groupB = 5
}
},
{
serverId = "def",
accessCode = "reserved-server-code",
groupUserCounts = {
groupB = 8
}
}
}
]]
local ActiveServers = {}
local function teleportPlayerToBestServer(player)
local success, chatGroups = pcall(function()
return TextChatService:GetChatGroupsAsync({ player })
end)
if not success or not chatGroups then
warn("Không thể lấy nhóm trò chuyện cho người chơi:", player.UserId)
return
end
-- Thu thập tất cả ID nhóm trò chuyện mà người chơi đủ điều kiện
local playerGroupIds = {}
for _, group in ipairs(chatGroups) do
for _, groupId in ipairs(group) do
playerGroupIds[groupId] = true
end
end
local bestServer = nil
local bestUserCount = 0
-- Chọn máy chủ có số lượng người dùng tương thích cao nhất
for _, server in ipairs(ActiveServers) do
local compatibleUserCount = 0
for groupId, userCount in pairs(server.groupUserCounts) do
if playerGroupIds[groupId] then
compatibleUserCount += userCount
end
end
if compatibleUserCount > bestUserCount then
bestUserCount = compatibleUserCount
bestServer = server
end
end
if not bestServer then
warn("Không tìm thấy máy chủ phù hợp cho người chơi:", player.UserId)
return
end
local ok, err = pcall(function()
TeleportService:TeleportToPrivateServer(
TARGET_PLACE_ID,
bestServer.accessCode,
{ player }
)
end)
if not ok then
warn("Di chuyển thất bại:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)
Lấy Nhóm Trò Chuyện Bất Đồng Bộ
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local players = Players:GetPlayers()
local success, chatGroups = pcall(function()
return TextChatService:GetChatGroupsAsync(players)
end)
if not success then
warn("Không thể lấy nhóm trò chuyện")
return
end
for _, group in ipairs(chatGroups) do
-- Mỗi nhóm chứa các chuỗi ID nhóm trò chuyện.
-- Người chơi có cùng ID nhóm có thể trò chuyện với nhau.
for _, groupId in ipairs(group) do
print("ID nhóm trò chuyện:", groupId)
end
end

Sự Kiện
BubbleDisplayed
Các khả năng: Chat
TextChatService.BubbleDisplayed(
partOrCharacter:Instance, textChatMessage:TextChatMessage
Tham Số
partOrCharacter:Instance
textChatMessage:TextChatMessage

MessageReceived
Các khả năng: Chat
TextChatService.MessageReceived(textChatMessage:TextChatMessage):RBXScriptSignal
Tham Số
textChatMessage:TextChatMessage

SendingMessage
Các khả năng: Chat
TextChatService.SendingMessage(textChatMessage:TextChatMessage):RBXScriptSignal
Tham Số
textChatMessage:TextChatMessage

Gọi Lại
OnBubbleAdded
Các khả năng: Chat
TextChatService.OnBubbleAdded(
message:TextChatMessage, adornee:Instance
Tham Số
adornee:Instance
Lợi Nhuận

OnChatWindowAdded
Các khả năng: Chat
TextChatService.OnChatWindowAdded(message:TextChatMessage):Tuple
Tham Số
Lợi Nhuận

OnIncomingMessage
Các khả năng: Chat
TextChatService.OnIncomingMessage(message:TextChatMessage):Tuple
Tham Số
Lợi Nhuận

©2026 Roblox Corporation. Roblox, logo Roblox và Powering Imagination là các nhãn hiệu đã đăng ký và chưa đăng ký của chúng tôi tại Hoa Kỳ và các quốc gia khác.