How to make a global messenger like grow a garden in studio lite!

Опубликовано: 14 Июнь 2026
на канале: Adtish9876a
96
2

server script service:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")

local remote = ReplicatedStorage:WaitForChild("GlobalAnnouncement")
local SOUND_ID = "rbxassetid://12221944"

-- Store active frames for stacking
local activeMessages = {}

-- Function to update positions of all active messages
local function updateStacking()
for i, frame in ipairs(activeMessages) do
if frame and frame.Parent then
frame:TweenPosition(
UDim2.new(0.5, -150, 0.1 + (i - 1) * 0.12, 0), -- stack with spacing
Enum.EasingDirection.Out,
Enum.EasingStyle.Quad,
0.3,
true
)
end
end
end

-- Function to broadcast announcement to all players in this server
local function broadcastToServer(message)
for _, plr in ipairs(Players:GetPlayers()) do
local playerGui = plr:FindFirstChild("PlayerGui")
if playerGui then
local gui = playerGui:FindFirstChild("GlobalMessageUI")
if not gui then
gui = Instance.new("ScreenGui")
gui.Name = "GlobalMessageUI"
gui.Parent = playerGui
end

local msgFrame = Instance.new("Frame")
msgFrame.Size = UDim2.new(0, 300, 0, 50)
msgFrame.Position = UDim2.new(0.5, -150, 0.1, 0)
msgFrame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
msgFrame.BackgroundTransparency = 0.9
msgFrame.Parent = gui

local corner = Instance.new("UICorner")
corner.CornerRadius = UDim.new(0, 5)
corner.Parent = msgFrame

-- Top & bottom white lines
for _, pos in ipairs({{0,0}, {0,1}}) do
local line = Instance.new("Frame")
line.Size = UDim2.new(1,0,0,2)
line.Position = UDim2.new(pos[1],0,pos[2],-2)
line.BackgroundColor3 = Color3.fromRGB(255,255,255)
line.Parent = msgFrame
end

local label = Instance.new("TextLabel")
label.Size = UDim2.new(1,-10,1,-10)
label.Position = UDim2.new(0,5,0,5)
label.BackgroundTransparency = 1
label.Text = message
label.TextColor3 = Color3.fromRGB(255,255,255)
label.TextScaled = true
label.Font = Enum.Font.GothamBold
label.TextStrokeTransparency = 0.7 -- shadow
label.Parent = msgFrame

-- Play sound once
local sound = Instance.new("Sound")
sound.SoundId = SOUND_ID
sound.Volume = 1
sound.PlayOnRemove = true
sound.Parent = msgFrame
sound:Destroy()

-- Add to active stack
table.insert(activeMessages, msgFrame)
updateStacking()

-- Remove after 5s and re-stack
task.delay(5, function()
for i, v in ipairs(activeMessages) do
if v == msgFrame then
table.remove(activeMessages, i)
break
end
end
if msgFrame then
msgFrame:Destroy()
end
updateStacking()
end)
end
end
end

-- Fired when someone submits announcement
remote.OnServerEvent:Connect(function(player, message)
local success, err = pcall(function()
MessagingService:PublishAsync("GlobalAnnouncements", message)
end)
if not success then
warn("Publish failed:", err)
end
end)

-- Listen for global announcements
local function subscribe()
local success, err = pcall(function()
MessagingService:SubscribeAsync("GlobalAnnouncements", function(msg)
broadcastToServer(msg.Data)
end)
end)
if not success then
warn("Subscribe failed:", err)
end
end

subscribe()