Kelas Engine
TextChatService
*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.
Rangkuman
Properti
Metode
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} |
Acara
BubbleDisplayed(partOrCharacter: Instance,textChatMessage: TextChatMessage):RBXScriptSignal |
MessageReceived(textChatMessage: TextChatMessage):RBXScriptSignal |
SendingMessage(textChatMessage: TextChatMessage):RBXScriptSignal |
Callback
OnBubbleAdded(message: TextChatMessage,adornee: Instance):Tuple |
OnChatWindowAdded(message: TextChatMessage):Tuple |
OnIncomingMessage(message: TextChatMessage):Tuple |
Referensi API
Properti
ChatVersion
Metode
CanUserChatAsync
CanUsersChatAsync
CanUsersDirectChatAsync
Memberikan nilai
Contoh Kode
CanUsersDirectChatAsync
local TextChatService = game:GetService("TextChatService")
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- Periksa peserta yang memenuhi syarat
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("Tidak dapat membuat TextChannel. Pengguna yang memenuhi syarat tidak cukup.")
return nilDisplayBubble
GetChatGroupsAsync
Parameter
players:Instances |
Memberikan nilai
Contoh Kode
TeleportPlayerToBestChatServer
-- Skrip Server
local TextChatService = game:GetService("TextChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- ID tempat tujuan
--[[
Status server di seluruh semesta yang di-stub.
Dalam praktiknya, data ini dapat disimpan dan diperbarui menggunakan MemoryStore
atau sistem backend lainnya.
Contoh bentuk:
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("Gagal mengambil grup obrolan untuk pemain:", player.UserId)
return
end
-- Kumpulkan semua ID grup obrolan yang dapat diakses pemain
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
-- Pilih server dengan jumlah pengguna yang kompatibel tertinggi
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("Tidak ada server yang sesuai ditemukan untuk pemain:", player.UserId)
return
end
local ok, err = pcall(function()
TeleportService:TeleportToPrivateServer(
TARGET_PLACE_ID,
bestServer.accessCode,
{ player }
)
end)
if not ok then
warn("Teleport gagal:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)Acara
BubbleDisplayed
TextChatService.BubbleDisplayed(
Parameter
MessageReceived
Parameter
SendingMessage
Parameter
Callback
OnBubbleAdded
Parameter
Memberikan nilai
OnChatWindowAdded
Parameter
Memberikan nilai
OnIncomingMessage
Parameter
Memberikan nilai