Notification Queue Help

How would I go about making a queueing system for my notifications?

Module:

local GUI = {}
local TweenService = game:GetService("TweenService")
local TransitionInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quad)
local Container = game.Players.LocalPlayer.PlayerGui.Notifacation.GUIHolder

function GUI:Alert(Text, Time, Color)
	local AlertLabel = script.Assets.AlertLabel
	local NewAlertLabel = AlertLabel:Clone()
	NewAlertLabel.Name = "Alert"
	NewAlertLabel.BackgroundColor3 = Color
	NewAlertLabel.Text = Text
	NewAlertLabel.Parent = Container
	TweenService:Create(NewAlertLabel, TransitionInfo, {BackgroundTransparency = 0}):Play()
	TweenService:Create(NewAlertLabel, TransitionInfo, {TextTransparency = 0}):Play()
	TweenService:Create(NewAlertLabel, TransitionInfo, {Position = UDim2.new(0.5, 0, 0.9, 0)}):Play()
	wait(Time)
	TweenService:Create(NewAlertLabel, TransitionInfo, {BackgroundTransparency = 1}):Play()
	TweenService:Create(NewAlertLabel, TransitionInfo, {TextTransparency = 1}):Play()
	local TweenWait = TweenService:Create(NewAlertLabel, TransitionInfo, {Position = UDim2.new(0.5, 0, 0.84, 0)})
	TweenWait:Play()
	
	TweenWait.Completed:Connect(function()
		NewAlertLabel:Destroy()
	end)
end

return GUI

Client:

local GUIModule = require(game.ReplicatedStorage.Modules.GUIModule)

GUIModule:Alert("the text", 5, Color3.fromRGB(255, 0, 0))
1 Like

dont use :
function GUI.Alert(Text, Time, Color)

the general idea of how I’d design it would be:

queue = {} -- an empty table
addedToQueue = a bindable event to notify the loop handling triggering the alerts to start if it's paused

function alert(...)
   same as your alert function except for the connection to .Completed
   Tween.Completed:Wait()
   delete the guiObject
end

function enQueue(...)
   insert a smaller table into the queue table the args you'd call alert(...) with
   fire addedToQueue
end

function handleQueue()
   while queue isnt empty
      call alert on the first item
      pop from queue with table.remove
   end

   addedToQueue.Event:Wait() -- wait until something is added to the queue
   handleQueue() -- continue handling the queue
end

and if you don’t like recursion, you could setup handleQueue() to have an infinite loop with while queue isnt empty and the :Wait() inside

how come? lol whats the difference

my bad

does it work

local GUI = {}
local Queue = {}

local QueueDelay = 0
local Alerted = false

local TweenService = game:GetService("TweenService")
local TransitionInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quad)
local Container = game.Players.LocalPlayer.PlayerGui.Notifacation.GUIHolder

function GUI:Alert(Text, Time, Color)
	if Alerted then
		table.insert(Queue, {Text, Time, Color})
		return
	end
	Alerted = true
	local AlertLabel = script.Assets.AlertLabel
	local NewAlertLabel = AlertLabel:Clone()
	NewAlertLabel.Name = "Alert"
	NewAlertLabel.BackgroundColor3 = Color
	NewAlertLabel.Text = Text
	NewAlertLabel.Parent = Container
	TweenService:Create(NewAlertLabel, TransitionInfo, {BackgroundTransparency = 0}):Play()
	TweenService:Create(NewAlertLabel, TransitionInfo, {TextTransparency = 0}):Play()
	TweenService:Create(NewAlertLabel, TransitionInfo, {Position = UDim2.new(0.5, 0, 0.9, 0)}):Play()
	
	wait(Time)
	
	TweenService:Create(NewAlertLabel, TransitionInfo, {BackgroundTransparency = 1}):Play()
	TweenService:Create(NewAlertLabel, TransitionInfo, {TextTransparency = 1}):Play()
	
	local TweenWait = TweenService:Create(NewAlertLabel, TransitionInfo, {Position = UDim2.new(0.5, 0, 0.84, 0)})
	TweenWait:Play()

	TweenWait.Completed:Connect(function()
		NewAlertLabel:Destroy()
		
		task.wait(QueueDelay)
		
		Alerted = false
		if #Queue > 0 then
			local QueueInfo = Queue[#Queue]
			
			table.remove(Queue[#Queue])
			GUI:Alert(table.unpack(QueueInfo))
		end
		
		
	end)
end

return GUI

you’d generally use . in this case because : gives the function access to use self

in this case, self is GUI, and you don’t need it

almost!

here my was error
image

script

local GUI = {}
local Queue = {}
local TweenService = game:GetService("TweenService")
local TransitionInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quad)
local Container = game.Players.LocalPlayer.PlayerGui.Notifacation.GUIHolder
local ZIndex_Alert = 100
local QueueDelay = 0
local Alerted = false

function GUI.Alert(Text, Time, Color)
	if Alerted then
		table.insert(Queue, {Text, Time, Color})
		return
	end
	Alerted = true
	local AlertLabel = script.Assets.AlertLabel
	local NewAlertLabel = AlertLabel:Clone()
	NewAlertLabel.Name = "Alert"
	NewAlertLabel.BackgroundColor3 = Color
	NewAlertLabel.Text = Text
	NewAlertLabel.ZIndex = ZIndex_Alert
	ZIndex_Alert += 1
	NewAlertLabel.Parent = Container
	TweenService:Create(NewAlertLabel, TransitionInfo, {BackgroundTransparency = 0}):Play()
	TweenService:Create(NewAlertLabel, TransitionInfo, {TextTransparency = 0}):Play()
	local TweenWait = TweenService:Create(NewAlertLabel, TransitionInfo, {Position = UDim2.new(0.5, 0, 0.94, 0)})
	TweenWait:Play()
	
	TweenWait.Completed:Connect(function()
		wait(Time)
		TweenService:Create(NewAlertLabel, TransitionInfo, {BackgroundTransparency = 1}):Play()
		TweenService:Create(NewAlertLabel, TransitionInfo, {TextTransparency = 1}):Play()
		local TweenWait = TweenService:Create(NewAlertLabel, TransitionInfo, {Position = UDim2.new(0.5, 0, 0.88, 0)})
		TweenWait:Play()
		
		TweenWait.Completed:Connect(function()
			NewAlertLabel:Destroy()
			task.wait(QueueDelay)
			Alerted = false
			if #Queue > 0 then
				local QueueInformation = Queue[#Queue]
				table.remove(Queue[#Queue])
				GUI.Alert(table.unpack(QueueInformation))
			end
		end)
	end)
end

return GUI

You need to use Color3 and not something else, try NewAlertLabel.BackgroundColor3 = Color3.fromRGB(0, 0, 0) or any other color

oops change this line

table.remove(Queue, #Queue)
1 Like

thank you! i noticed that it doesnt display the notifications the client sends in order it kinda randomizes it a bit, for example it usually does β€œ1”, β€œ5”, β€œ4”, β€œ3”, and β€œ2”

client

local GUIModule = require(game.ReplicatedStorage.Modules.GUIModule)

GUIModule.Alert("alert 1", 5, Color3.fromRGB(255, 70, 95))
wait(0.1)
GUIModule.Alert("alert 2", 5, Color3.fromRGB(255, 85, 0))
wait(0.1)
GUIModule.Alert("alert 3", 5, Color3.fromRGB(0, 0, 255))
wait(0.1)
GUIModule.Alert("alert 4", 5, Color3.fromRGB(0, 0, 0))
wait(0.1)
GUIModule.Alert("alert 5", 5, Color3.fromRGB(77, 77, 77))

If anyone knows how I could have this queue in order, lemme know!

1 Like

if it happens in reverse then use 1 instead of #Queue

local GUI = {}
local Queue = {}
local TweenService = game:GetService("TweenService")
local TransitionInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quad)
local Container = game.Players.LocalPlayer.PlayerGui.Notifacation.GUIHolder
local ZIndex_Alert = 100
local QueueDelay = 0
local Alerted = false

function GUI.Alert(Text, Time, Color)
	if Alerted then
		table.insert(Queue, {Text, Time, Color})
		return
	end
	Alerted = true
	local AlertLabel = script.Assets.AlertLabel
	local NewAlertLabel = AlertLabel:Clone()
	NewAlertLabel.Name = "Alert"
	NewAlertLabel.BackgroundColor3 = Color
	NewAlertLabel.Text = Text
	NewAlertLabel.ZIndex = ZIndex_Alert
	ZIndex_Alert += 1
	NewAlertLabel.Parent = Container
	TweenService:Create(NewAlertLabel, TransitionInfo, {BackgroundTransparency = 0}):Play()
	TweenService:Create(NewAlertLabel, TransitionInfo, {TextTransparency = 0}):Play()
	local TweenWait = TweenService:Create(NewAlertLabel, TransitionInfo, {Position = UDim2.new(0.5, 0, 0.94, 0)})
	TweenWait:Play()

	TweenWait.Completed:Connect(function()
		wait(Time)
		TweenService:Create(NewAlertLabel, TransitionInfo, {BackgroundTransparency = 1}):Play()
		TweenService:Create(NewAlertLabel, TransitionInfo, {TextTransparency = 1}):Play()
		local TweenWait = TweenService:Create(NewAlertLabel, TransitionInfo, {Position = UDim2.new(0.5, 0, 0.88, 0)})
		TweenWait:Play()

		TweenWait.Completed:Connect(function()
			NewAlertLabel:Destroy()
			task.wait(QueueDelay)
			Alerted = false
			
			if #Queue > 0 then
				local QueueInformation = Queue[1]
				table.remove(Queue, 1)
				
				GUI.Alert(table.unpack(QueueInformation))
			end
		end)
	end)
end

return GUI

I got this error again with your new script

huh

table.remove(Queue, 1)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.