エンジンクラス
TextChatService
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
プロパティ
方法
CanUserChatAsync(userId: User):boolean |
CanUsersChatAsync(userIdFrom: User,userIdTo: User):boolean |
CanUsersDirectChatAsync(requesterUserId: User,userIds: {any}):{any} |
DisplayBubble(partOrCharacter: Instance,message: string):() |
GetChatGroupsAsync(players: Instances):{any} |
イベント
BubbleDisplayed(partOrCharacter: Instance,textChatMessage: TextChatMessage):RBXScriptSignal |
MessageReceived(textChatMessage: TextChatMessage):RBXScriptSignal |
SendingMessage(textChatMessage: TextChatMessage):RBXScriptSignal |
コールバック
OnBubbleAdded(message: TextChatMessage,adornee: Instance):Tuple |
OnChatWindowAdded(message: TextChatMessage):Tuple |
OnIncomingMessage(message: TextChatMessage):Tuple |
APIリファレンス
プロパティ
ChatVersion
方法
CanUsersChatAsync
CanUsersDirectChatAsync
戻り値
コードサンプル
ユーザーが直接チャットできるか非同期で確認
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 nilDisplayBubble
GetChatGroupsAsync
パラメータ
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
TextChatService.BubbleDisplayed(
パラメータ
MessageReceived
パラメータ
SendingMessage
パラメータ
コールバック
OnBubbleAdded
パラメータ
戻り値
OnChatWindowAdded
パラメータ
戻り値
OnIncomingMessage
パラメータ
戻り値