学习
引擎类
MessagingService
无法创建
服务
未复制

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


概要
方法
PublishAsync(topic: string,message: Variant):()
继承成员

API 参考
方法
PublishAsync
暂停
功能: ServerCommunication
MessagingService:PublishAsync(
topic:string, message:Variant
):()
参数
topic:string
message:Variant
返回
()

SubscribeAsync
暂停
功能: ServerCommunication
MessagingService:SubscribeAsync(
topic:string, callback:function
参数
topic:string
callback:function
代码示例
订阅跨服务器消息
local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")
local function onPlayerAdded(player)
-- 订阅主题
local topic = "player-" .. player.UserId
local connection = MessagingService:SubscribeAsync(topic, function(message)
print("接收到的消息来自", player.Name, message.Data)
end)
player.AncestryChanged:Connect(function()
-- 取消订阅主题
connection:Disconnect()
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)

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