요약
속성
메서드
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
반환
코드 샘플
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