I’m new to the MessagingService but I want to try to send 2 variables through it so I can make an Announcements system for my game. I am trying to put the variables in a table like this and Publish it
local MessagingService = game:GetService("MessagingService")
game.ReplicatedStorage.RemoteEvents.Main.Global.MSAnnounce.OnServerEvent:Connect(function(plr, Text, Title)
local message = {
Text = Text,
Title = Title
}
MessagingService:PublishAsync("MSAnnouncement", message)
end)
and send it to another script to Subscribe to it like this
local MessagingService = game:GetService("MessagingService")
local function Event(message)
local players = game:GetService("Players"):GetPlayers()
for _, player in ipairs(players) do
-- Get the PlayerGui instance of the player
local gui = player:WaitForChild("PlayerGui").NoticeNotification.Frame
-- Tween the position of the gui
gui.Description.Text = message.Text
gui.Title.Text = message.Title
end
end
MessagingService:SubscribeAsync("MSAnnouncement", function(message)
Event(message)
end)
After it triggers the Event() function and sets the text to the “Text” and “Title” values, the text becomes nil. I have put print functions to check and only after I Publish it then the text becomes nil. I have tried Encoding the table, Decoding the table, message.Data.text, and more different stuff but it is nil.
I probably dont know everything about the MessagingService or how tables work but any help will be appreciated on how I can set these 2 TextLabels to have the text from a table with variables in messaging services.