เรียนรู้
Engine Class
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 เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ