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
BirdieI90
(Ping)
December 25, 2022, 8:20am
#3
dont use :
function GUI.Alert(Text, Time, Color)
4SHN
(steve)
December 25, 2022, 8:22am
#4
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
BirdieI90
(Ping)
December 25, 2022, 2:09pm
#7
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
4SHN
(steve)
December 25, 2022, 9:29pm
#8
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
BirdieI90:
does it work
almost!
here my was error
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
BirdieI90
(Ping)
December 26, 2022, 11:19am
#14
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
BirdieI90
(Ping)
December 27, 2022, 8:50am
#18
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
ThinkingAIINight:
system
(system)
Closed
January 10, 2023, 9:11am
#21
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.