学习
引擎类
VoiceChatService
无法创建
服务

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处



API 参考
属性
DefaultDistanceAttenuation
插件安全性
读取并联
功能: Audio, Chat
VoiceChatService.DefaultDistanceAttenuation:Enum.VoiceChatDistanceAttenuationType

EnableDefaultVoice
插件安全性
读取并联
功能: Audio, Chat
VoiceChatService.EnableDefaultVoice:boolean

UseAudioApi
插件安全性
读取并联
功能: Audio, Chat
VoiceChatService.UseAudioApi:Enum.AudioApiRollout

方法
GetChatGroupsAsync
暂停
功能: Audio, Chat
VoiceChatService:GetChatGroupsAsync(players:Instances):{any}
参数
players:Instances
返回
代码示例
传送玩家至最佳聊天服务器
-- 服务器脚本
local VoiceChatService = game:GetService("VoiceChatService")
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 VoiceChatService: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)

IsVoiceEnabledForUserIdAsync
暂停
功能: Audio, Chat
VoiceChatService:IsVoiceEnabledForUserIdAsync(userId:User):boolean
参数
userId:User
返回

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。