Hello fellow scripters, I’ve been thinking of making a global nuke for fun but couldn’t really come up on how to contact other server’s if someone bought a dev product. Could someone tell me how to do that?
this i guess
local Players = game:GetService("Players")
local httpService = game:GetService("HttpService")
local messagingService = game:GetService("MessagingService")
function callbackFunction(serviceData)
local decodedData = httpService:JSONDecode(serviceData.data)
print(decodedData.sender.." : "..decodedData.message)
end)
Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(msg)
local messageData = {
sender = player,
message = msg, -- filter message first!
}
local encoded = httpService:JSONEncode(messageData)
messagingService:PublishAsync("Chat", encoded)
end)
end)
messagingService:SubscribeAsync("Chat", callbackFunction)
this is with JSONDecode but you can make it without)
Could you give a little example? Thank you.
I have a question, which part of the script receives the message?
messagingService:SubscribeAsync(“Chat”, callbackFunction) – this one it calls the function when the new data got published
So it will only run once or multiple times so every time a message gets sent it runs?
Every time when someone chatted it will print who chatted and the message in every server. I can simplify if you want.
Thank you so much! Really appreciate your help.
Just started testing and it turned out to have an error, Argument 1 mission or nil
local decodedData = httpService:JSONDecode(serviceData.data)
local Players = game:GetService("Players")
local httpService = game:GetService("HttpService")
local messagingService = game:GetService("MessagingService")
function callbackFunction(serviceData)
local decodedData = httpService:JSONDecode(serviceData.data)
print(decodedData.sender.." : "..decodedData.message)
end)
Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(msg)
local messageData = {
sender = player,
message = msg, -- filter message first!
}
local mainData = {}
mainData["data"] = messageData
local encoded = httpService:JSONEncode(messageData)
messagingService:PublishAsync("Chat", encoded)
end)
end)
messagingService:SubscribeAsync("Chat", callbackFunction)
oops didn’t added any “data”
Still, I am getting the same error.
Fixing in roblox studio wait a bit.
local Players = game:GetService("Players")
local httpService = game:GetService("HttpService")
local messagingService = game:GetService("MessagingService")
function callbackFunction(serviceData)
local decodedData = httpService:JSONDecode(serviceData)
print(decodedData)
end
Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(msg)
local messageData = {msg = msg}
local encoded = httpService:JSONEncode(messageData)
messagingService:PublishAsync("Chat", encoded)
end)
end)
messagingService:SubscribeAsync("Chat", callbackFunction)
try this one
Doesn’t bring up an error but it prints nothing.
Alright it shouldn’t print it in chat tho it prints in console
local Players = game:GetService("Players")
local httpService = game:GetService("HttpService")
local messagingService = game:GetService("MessagingService")
Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(msg)
messagingService:PublishAsync("Chat", msg)
end)
end)
messagingService:SubscribeAsync("Chat", function(msg)
print(msg.Data)
end)
It prints the msg as a table in output, I’ll try fixing and I’ll tell you if I’ll succeed.
1 More question, is there a way to send the player name who sent the message?
i can’t get myself why it gives a talbe in output…
Already fixed that by using]
print(msg.Data)