Roblox · Интерфейсы
Справа внизу всплывают сообщения: «Квест выполнен», «+10 монет», «Игрок зашёл». Цветная полоска, плавное появление, сами исчезают. Отправить можно из любого скрипта одной строкой.
Синим — что нужно создать.
ReplicatedStorage ├─ NotifyEvent (RemoteEvent) — сервер → игрок └─ NotifyLocal (BindableEvent) — локальные скрипты → уведомление ServerScriptService ├─ Notify (ModuleScript) — Send, All └─ NotifyDemo (Script) — пример (по желанию) StarterGui └─ NotifyGui (ScreenGui) — ResetOnSpawn выкл. ├─ List (Frame) — UIListLayout, VerticalAlignment Bottom │ └─ Sample (CanvasGroup) — шаблон: Stripe (Frame), Label (TextLabel) ├─ Ding (Sound) └─ NotifyLocal (LocalScript)
Где: ServerScriptService · ModuleScript
Зачем: Отправка уведомлений.
-- общее хранилище
local RS = game:GetService("ReplicatedStorage")
-- RemoteEvent уведомлений
local event = RS:WaitForChild("NotifyEvent")
-- таблица модуля
local Notify = {}
-- уведомление одному игроку
function Notify.Send(player, text, color)
-- отправляем
event:FireClient(player, text, color)
-- конец функции
end
-- уведомление всем
function Notify.All(text, color)
-- отправляем всем
event:FireAllClients(text, color)
-- конец функции
end
-- отдаём модуль
return NotifyГде: StarterGui → NotifyGui · LocalScript
Зачем: Показ уведомлений.
-- общее хранилище
local RS = game:GetService("ReplicatedStorage")
-- плавное появление
local TweenService = game:GetService("TweenService")
-- от сервера
local event = RS:WaitForChild("NotifyEvent")
-- BindableEvent — от локальных скриптов
local localEvent = RS:WaitForChild("NotifyLocal")
-- NotifyGui
local gui = script.Parent
-- столбик уведомлений
local list = gui:WaitForChild("List")
-- шаблон
local sample = list:WaitForChild("Sample")
-- звук (если есть)
local sound = gui:FindFirstChild("Ding")
-- секунд на экране
local SHOW_TIME = 4
-- больше 5 сразу — старые уходят
local MAX = 5
-- цвет полоски по умолчанию
local DEFAULT_COLOR = Color3.fromRGB(80, 160, 255)
-- номер уведомления — для порядка
local counter = 0
-- плавно убрать
local function Hide(toast)
-- уже убрано
if not toast.Parent then return end
-- тает
local fade = TweenService:Create(toast, TweenInfo.new(0.4), {GroupTransparency = 1})
-- запускаем
fade:Play()
-- ждём
fade.Completed:Wait()
-- удаляем
toast:Destroy()
-- конец функции
end
-- показать уведомление
local function Show(text, color)
-- следующий номер
counter += 1
-- копия шаблона
local toast = sample:Clone()
-- имя
toast.Name = "Toast"
-- новые — ниже
toast.LayoutOrder = counter
-- текст
toast.Label.Text = text
-- цветная полоска слева
toast.Stripe.BackgroundColor3 = color or DEFAULT_COLOR
-- сначала прозрачное
toast.GroupTransparency = 1
-- шаблон был скрыт
toast.Visible = true
-- в столбик
toast.Parent = list
-- проявляется
TweenService:Create(toast, TweenInfo.new(0.3), {GroupTransparency = 0}):Play()
-- звук
if sound then sound:Play() end
-- все показанные
local toasts = {}
-- дети столбика
for _, child in ipairs(list:GetChildren()) do
-- только уведомления
if child.Name == "Toast" then table.insert(toasts, child) end
-- конец перебора
end
-- старые — первыми
table.sort(toasts, function(a, b) return a.LayoutOrder < b.LayoutOrder end)
-- лишние старые убираем
for i = 1, #toasts - MAX do toasts[i]:Destroy() end
-- через 4 секунды убрать
task.delay(SHOW_TIME, Hide, toast)
-- конец функции
end
-- уведомление от сервера
event.OnClientEvent:Connect(Show)
-- уведомление от локального скрипта
localEvent.Event:Connect(Show)Где: ServerScriptService · Script
Зачем: Пример использования.
-- игроки
local Players = game:GetService("Players")
-- модуль уведомлений
local Notify = require(game:GetService("ServerScriptService"):WaitForChild("Notify"))
-- плита для проверки
local plate = workspace:WaitForChild("NotifyPlate")
-- кому недавно показывали
local cooldown = {}
-- игрок зашёл
Players.PlayerAdded:Connect(function(player)
-- всем
Notify.All(player.DisplayName .. " зашёл в игру", Color3.fromRGB(120, 200, 255))
-- даём интерфейсу загрузиться
task.wait(3)
-- только ему
Notify.Send(player, "Добро пожаловать! Встань на жёлтую плиту", Color3.fromRGB(255, 210, 60))
-- конец функции
end)
-- касание плиты
plate.Touched:Connect(function(hit)
-- игрок?
local player = Players:GetPlayerFromCharacter(hit.Parent)
-- не игрок или недавно было
if not player or cooldown[player] then return end
-- пауза
cooldown[player] = true
-- уведомление
Notify.Send(player, "+10 монет (пример)", Color3.fromRGB(90, 220, 110))
-- 2 секунды
task.wait(2)
-- можно снова
cooldown[player] = nil
-- конец функции
end)Запусти Play (или Run) и убедись: