學習
引擎類別
TextChatService
無法建立
服務

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡



API 參考
屬性
ChatTranslationEnabled
未複製
Roblox 指令碼安全性
平行讀取
功能: Chat
TextChatService.ChatTranslationEnabled:boolean

ChatVersion
已棄用

CreateDefaultCommands
外掛程式安全性
平行讀取
功能: Chat
TextChatService.CreateDefaultCommands:boolean

CreateDefaultTextChannels
外掛程式安全性
平行讀取
功能: Chat
TextChatService.CreateDefaultTextChannels:boolean

方法
CanUserChatAsync
暫停
功能: Chat
TextChatService:CanUserChatAsync(userId:User):boolean
參數
userId:User
返回

CanUsersChatAsync
暫停
功能: Chat
TextChatService:CanUsersChatAsync(
userIdFrom:User, userIdTo:User
參數
userIdFrom:User
userIdTo:User
返回

CanUsersDirectChatAsync
暫停
功能: Chat
TextChatService:CanUsersDirectChatAsync(
requesterUserId:User, userIds:{any}
參數
requesterUserId:User
userIds:{any}
返回
範例程式碼
兩位使用者可以直接聊天的非同步檢查
local TextChatService = game:GetService("TextChatService")
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- 檢查 是否有合格的參與者
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("無法創建 TextChannel。可用使用者不足。")
return nil

DisplayBubble
功能: Chat
TextChatService:DisplayBubble(
partOrCharacter:Instance, message:string
):()
參數
partOrCharacter:Instance
message:string
返回
()

GetChatGroupsAsync
暫停
功能: Chat
TextChatService:GetChatGroupsAsync(players:Instances):{any}
參數
players:Instances
返回
範例程式碼
傳送玩家到最佳聊天伺服器
-- 伺服器腳本
local TextChatService = game:GetService("TextChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- 目標場地 ID
--[[
存根的全宇宙範圍伺服器狀態。
在實際中,這些數據可以使用 MemoryStore
或其他後端系統來存儲和更新。
示例形狀:
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("無法檢索玩家的聊天組:", player.UserId)
return
end
-- 收集玩家有資格的所有聊天組 ID
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
-- 選擇擁有最多兼容用戶的伺服器
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("未找到適合的伺服器給玩家:", player.UserId)
return
end
local ok, err = pcall(function()
TeleportService:TeleportToPrivateServer(
TARGET_PLACE_ID,
bestServer.accessCode,
{ player }
)
end)
if not ok then
warn("傳送失敗:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)

活動
BubbleDisplayed
功能: Chat
TextChatService.BubbleDisplayed(
partOrCharacter:Instance, textChatMessage:TextChatMessage
參數
partOrCharacter:Instance
textChatMessage:TextChatMessage

MessageReceived
功能: Chat
TextChatService.MessageReceived(textChatMessage:TextChatMessage):RBXScriptSignal
參數
textChatMessage:TextChatMessage

SendingMessage
功能: Chat
TextChatService.SendingMessage(textChatMessage:TextChatMessage):RBXScriptSignal
參數
textChatMessage:TextChatMessage

回調
OnBubbleAdded
功能: Chat
TextChatService.OnBubbleAdded(
message:TextChatMessage, adornee:Instance
參數
adornee:Instance
返回

OnChatWindowAdded
功能: Chat
TextChatService.OnChatWindowAdded(message:TextChatMessage):Tuple
參數
返回

OnIncomingMessage
功能: Chat
TextChatService.OnIncomingMessage(message:TextChatMessage):Tuple
參數
返回

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。