學習
引擎類別
MessagingService
無法建立
服務
未複製

*此內容是使用 AI(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 是我們在美國及其他國家地區的部分註冊與未註冊商標。