How would I go about developing game-wide broadcast system for developers via MessagingService?

Stupidly, I forgot a bit of the main part. My goal to achieve was to transfer the message to a textlabel in all servers. How would I go about that part? Thank you for your continued help so far.

Hm, alright. I was always under the impression that something like this was still developer set text even though it wasn’t set in studio.

I’ll be honest with you, I might be wrong, but in my opinion it is better safe than sorry, especially if your account gets compromised or something goes wrong, because then you will be held at fault.

1 Like

That’s very true, but that’s also where 2 factor authentication comes in to play. (Doesn’t counter cookie stealing though so that’s where you would need to be careful.)

Also there’s no reason not to filter it, but if you try to say “X event happening and Y time” and y gets filtered. /shrug

Create a TextLabel in a ScreenGui and then, when the server gets a message using MessagingService, send this message to all of the clients with a RemoteEvent (you could use the same one you did before).

MessagingService:SubscribeAsync(BroadcastTopic, function(message)
	-- Do stuff with "message" here
	BroadcastEvent:FireAllClients(message)
end)

Then, in the TextLabel, add a LocalScript that looks something like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local BroadcastEvent = ReplicatedStorage:WaitForChild("GlobalBroadcast")

BroadcastEvent.OnClientEvent:Connect(function(message)
	script.Parent.Text = message
	wait(5)
	script.Parent.Text = ""
end)

You will obviously need to set up the UI design/scripting how you see fit for your game.

A script in ServerScriptService:

local MessagingService = game:GetService("MessagingService")

local TextService = game:GetService("TextService")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Box = game.StarterGui.ScreenGui.Frame.BroadcastMessageInput

local BroadcastEvent = ReplicatedStorage:WaitForChild("GlobalBroadcast")

local BroadcastTopic = "GlobalBroadcast"

local function FilterStringAsync(Text, Player)

local FilteredText = "" -- Nothing yet

local Success, Error = pcall(function() -- Wrap in pcall in case filtering API errors

local FilteredTextResult = TextService:FilterStringAsync(Text, Player.UserId)

FilteredText = FilteredTextResult:GetNonChatStringForBroadcastAsync()

end)

return FilteredText

end

MessagingService:SubscribeAsync(BroadcastTopic, function(message)

message = Box.Text -- Do stuff with "message" here

BroadcastEvent:FireAllClients(message)

end)

BroadcastEvent.OnServerEvent:Connect(function(player, message)

local StringToSend = FilterStringAsync(message, player)

MessagingService:PublishAsync(BroadcastTopic, StringToSend)

end)

LocalScript Under the TextBox:

 local Box = script.Parent
local GlobalBroadcast = game.ReplicatedStorage.GlobalBroadcast

Box.FocusLost:Connect(function(enter_pressed)
	if enter_pressed then
		GlobalBroadcast:FireServer(Box.Text)
	end
end)

LocalScript under the label:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local BroadcastEvent = ReplicatedStorage:WaitForChild("GlobalBroadcast")

BroadcastEvent.OnClientEvent:Connect(function(message)

script.Parent.Text = message

wait(5)

script.Parent.Text = ""

end)

What I have done so far

You are still using the StarterGui text instead of the message that was pased by the client. I explained earlier in the thread why you should basically never touch StarterGui when getting information from clients above.

I also posted a script that should function fine. Have you read through it and implemented changes?

I am juggling something in real life and doing this, so yes but slowly.

How do I go about changing that?

I explained and gave code above in the thread. Feel free to just copy and paste if you’d like, just make sure you understand for future reference.

When you fired the RemoteEvent from the client, you sent the message that was typed to the server already. So, on the script, you can use that argument that was passed by the client directly in the function for the event. Currently, you are referencing the TextBox located in StarterGui, which will not update based on what the user types.

Apologies, I get confused regularly, can you place a --“note” where I need to fix it? and I will do so, thanks!

You don’t need to do message = Box.Text because the message is already being given to you by subscribing to the topic. You can just remove that one part and all should be good :slight_smile:

1 Like

God damn it, I was starting at the line of text for like 20 minutes and then was like “alright i’ll mess this up somehow if I remove it”, I guess should of gone with instincts

I do not consider myself a programmer anymore looool

Hey, got this in the output, tried to fix it, but getting no luck here.

Hello, can you send the latest versions of all of your scripts?

1 Like

This is the script in serverscriptservice:

local MessagingService = game:GetService("MessagingService")

local TextService = game:GetService("TextService")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Box = game.StarterGui.ScreenGui.Frame.BroadcastMessageInput

local BroadcastEvent = ReplicatedStorage:WaitForChild("GlobalBroadcast")

local BroadcastTopic = "GlobalBroadcast"

local function FilterStringAsync(Text, Player)

local FilteredText = "" -- Nothing yet

local Success, Error = pcall(function() -- Wrap in pcall in case filtering API errors

local FilteredTextResult = TextService:FilterStringAsync(Text, Player.UserId)

FilteredText = FilteredTextResult:GetNonChatStringForBroadcastAsync()

end)

return FilteredText

end

MessagingService:SubscribeAsync(BroadcastTopic, function(message)

BroadcastEvent:FireAllClients(message)

end)

BroadcastEvent.OnServerEvent:Connect(function(player, message)

local StringToSend = FilterStringAsync(message, player)

MessagingService:PublishAsync(BroadcastTopic, StringToSend)

end)

LocalScript under the textlabel that displays:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local BroadcastEvent = ReplicatedStorage:WaitForChild("GlobalBroadcast")

BroadcastEvent.OnClientEvent:Connect(function(message)
	script.Parent.Text = message
		wait(5)
	script.Parent.Text = ""
end)

LocalScript under the broadcast textbox to type in the message (devs only thing)

local Box = script.Parent

local GlobalBroadcast = game.ReplicatedStorage.GlobalBroadcast

Box.FocusLost:Connect(function(enter_pressed)

if enter_pressed then

GlobalBroadcast:FireServer(Box.Text)

end

end)

Ah! My mistake. I had forgotten exactly how MessagingService works. Replace BroadcastEvent:FireAllClients(message) with BroadcastEvent:FireAllClients(message.Data) and you should be good to go :slight_smile:

Thanks, I will be updating my UI so it looks nice, and will make it so that only I can open that gui.

I made a model for this.

1 Like

Feel free to mark the most helpful reply here as the solution to help any others who find this thread having the same issue.