Global announcement not working

Hey there,

I have a script that allows me to send a global announcement out to all players in all servers. Though it is currently just acting as a normal announcement server-script.

Here it is:

local Players = game:GetService("Players")
local MessagingService = game:GetService("MessagingService")

local Queue = {}

local function DisplayAnnouncement(context, text)
	print("Displaying announcement: '" .. text .. "'")
	if context and context.Reply then
		context:Reply("Displaying announcement '" .. text .. "'")
	end

	for _, player in ipairs(Players:GetPlayers()) do
		table.insert(Queue, context)
		repeat task.wait() until Queue[1] == context

		local ScreenGui, Tweens, Timer = script.Message:Clone(), {}, 20
		ScreenGui.Parent = player.PlayerGui
		ScreenGui.Enabled = true

		local function AnimateText(Text)
			for i = 1, #Text, 1 do
				ScreenGui.Announcement.MainFrame.Wrapper.Container.Desc.Text = string.sub(Text, 1, i)
				wait(0.07)
			end
		end

		Tweens["Canvas"] = game:GetService("TweenService"):Create(ScreenGui.Announcement, TweenInfo.new(0.5, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), { GroupTransparency = 0, Position = UDim2.fromScale(0.5, 0.225) })
		Tweens["Canvas"]:Play()

		ScreenGui.Announcement.Visible = true
		AnimateText(text)

		local countdownLabel = ScreenGui.Announcement.MainFrame.Wrapper.Topbar.Right.Timer
		if countdownLabel and countdownLabel:IsA("TextLabel") then
			for i = 15, 1, -1 do
				countdownLabel.Text = tostring(i)
				task.wait(1)
			end
		end

		Tweens["Canvas"] = game:GetService("TweenService"):Create(ScreenGui.Announcement, TweenInfo.new(0.5, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), { GroupTransparency = 1, Position = UDim2.fromScale(0.5, 0.275) })
		Tweens["Canvas"]:Play()

		task.wait(0.5)

		ScreenGui:Destroy()
		table.remove(Queue, 1)
	end

	return ""
end

MessagingService:SubscribeAsync("GlobalAnnouncement", function(message)
	print("Received global announcement: '" .. message.Data .. "'")
	local text = message.Data
	for _, player in ipairs(Players:GetPlayers()) do
		DisplayAnnouncement({ Reply = function(_) end }, text)
	end
end)

return function(context, text)
	print("Publishing global announcement: '" .. text .. "'")
	local success, errorMessage = pcall(function()
		MessagingService:PublishAsync("GlobalAnnouncement", text)
	end)
	if not success then
		warn("Error publishing message: " .. errorMessage)
	end
	return ""
end

(and yes I am using Cmdr, though that does not affect anything AFAIK.)

Thanks for your help :heart:

3 Likes

Here is a long but informative tutorial:

and here is a quick free model tutorial if you want that : )

I’ve used tutorials but they just suck compared to what I’m trying to do, they are using text commands and also everything they are doing is what I have done so I have no idea what I’m doing wrong.

Maybe a modified version of my code would be better?

EDIT: I mean, all my script is on the server, so maybe it would be better to split it up? But I have no idea where to start to split it, if anyone could help me on that it would be fantastic :heart:

Can you elaborate on what’s going wrong? Also,

for _, player in ipairs(Players:GetPlayers()) do
    DisplayAnnouncement({ Reply = function(_) end }, text)
end

DisplayAnnouncement already iterates over all in-game players. Calling DisplayAnnouncement this way would only cause out-of-sync duplication. Change your code to:

DisplayAnnouncement({ Reply = function(_) end }, text)
1 Like

Literally, all of the prints will only print in the server that the command is being activated on. Nothing is being recieved by the other server.

And there is no errors whatsoever. I’ll send the output below on both sides:

Sender: (roblox client)

image

Reciever: (roblox studio client)

(nothing)

I’m sorry, are you trying to send an announcement from a live game session, and are attempting to receive it in a Roblox Studio session?

Yes, from previous experiences that’s worked, unless I’m being dumb it should still be working?

EDIT: Also there is no other way to get a seperate server unless I use private servers but the game itself is set to private so I cannot do that.

Roblox Studio sessions are not real Roblox servers. A deployed Roblox server would attempt to contact other deployed Roblox servers, not your locally-hosted server

Ah okay.

I’ll try to get 2 seperate servers without using private servers and I’ll update you on how that goes

The code looks fine to me, so I don’t suspect any issues. On another note, the client should be handling the announcement GUI, not the server. If any latency issues occur, the GUI could be frozen to the user’s screen, or abruptly removed

It seems to work just fine. I’ll dm you if it stops working or breaks at any point

1 Like