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