Since you are unable to send Data with MessagingService in Studio, here is a module on how to use a mock version of MessagingService
local MessagingService = game:GetService("MessagingService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local BindableEvent = Instance.new("BindableEvent")
local mockMessagingService = {
SubscribeAsync = function(_, topic, callback)
BindableEvent.Event:Connect(function(publishedTopic, data)
if publishedTopic == topic then
callback({Data = data})
end
end)
end,
PublishAsync = function(_, topic, data)
BindableEvent:Fire(topic, data)
end
}
local useMock = RunService:IsStudio()
local activeMessagingService = useMock and mockMessagingService or MessagingService
return activeMessagingService
Or click here for the module: MessagingService (for Studio playtesting)
How it works and how to use it
The module works by checking if you are currently in studio and if you are, it will use a BindableEvent in order to send information instead of the service. The event names are changed and other parameters in order that in the case you playtest not in Studio, there will be no difference from what you have tested in Studio.
local MessagingService = require(script.mockMessage) -- change path if needed
MessagingService:SubscribeAsync("Test", function(message)
local data = message.Data
print(data["test"])
end)
local t = {
test = "hi"
}
MessagingService:PublishAsync("Test", t)
// Studio
// in game
ᶦᶠ ᵗʰᵉʳᵉ ᶦˢ ᵃˡʳᵉᵃᵈʸ ᵃ ᵐᵒᵈᵘˡᵉ ᶠᵒʳ ᵗʰᵃᵗ ᵗʰᵉⁿ ᵐᵇ