Engine Class
MessagingService
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
สรุป
วิธีการ
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)