概要
方法
PublishAsync(topic: string,message: Variant):() |
SubscribeAsync(topic: string,callback: function):RBXScriptConnection |
API 參考
方法
PublishAsync
SubscribeAsync
範例程式碼
訂閱跨伺服器消息
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)