GUI Queueing Help

When clicking 2 of the alert activation parts, and after the first alert plays, an error occurs and I don’t know why it’s getting nil when it clearly inserts the data into the Queue table.

Error:
image

GUI Module:

local GUI = {}
local Queue = {}
local TweenService = game:GetService("TweenService")
local TransitionInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quad)
local IsAlerting = false

function GUI.Alert(Text, Time, Color, Player)
	if IsAlerting then
		table.insert(Queue, {Text, Time, Color, Player})
		return
	end
	IsAlerting = true
	local AlertLabel = script.Assets.AlertLabel
	local NewAlertLabel = AlertLabel:Clone()
	NewAlertLabel.Name = "Alert"
	NewAlertLabel.BackgroundColor3 = Color
	NewAlertLabel.Text = Text
	NewAlertLabel.Parent = game.Players[tostring(Player)].PlayerGui.Notifacation.GUIHolder
	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()
			IsAlerting = false
			if #Queue >= 1 then
				table.remove(Queue, 1)
				wait(0.5)
				GUI.Alert(table.unpack(Queue[1])) --Error line #38
			end
		end)
	end)
end

return GUI

Snippet of the 2 activation parts (module):

function Restock.ColdDrinkCup(Player, ItemPath)
	deletesoon_guimodule.Alert("Sorry but the Cold Drink Cup restock item isn't available at this time!", 5, Color3.fromRGB(255, 34, 34), Player)
end

function Restock.TakeawayCup(Player, ItemPath)
	deletesoon_guimodule.Alert("Sorry but the Takeaway Cup restock item isn't available at this time!", 5, Color3.fromRGB(255, 34, 34), Player)
end
1 Like

you’re removing the queued item without saving it in any variables. The subsequent Queue[1] is then nil if there was only a single item in the queue. Try

local queuedAlert = table.remove(Queue, 1)
GUI.Alert(table.unpack(queuedAlert))

which is the same as

local queuedAlert = Queue[1]
table.remove(Queue, 1)
GUI.Alert(table.unpack(queuedAlert))

or even

GUI.Alert(table.unpack(table.remove(Queue, 1)))
2 Likes

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