Queuing Help using Module

I made this Module and it works well but the only issues that I just found out was queuing issues. What happens is it queues for ALL events and not an induvial queue.

When sending out an alert for ALL players, each player is queued up and gets the alert one at a time which is what I don’t want, I want everyone to have there own queue.

Let me know if you know how to slove this.

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
				wait(0.25)
				GUI.Alert(table.unpack(table.remove(Queue, 1)))
			end
		end)
	end)
end

return GUI
2 Likes

What exactly are you queueing for? The way you phrased your question is rather confusing.

It would require some rewriting but probably the best way would be to send the info to a queue on the client then use a remote event trigger from the server to release them all together.

Or,

You could have individual queues by indexing the player inside the queue table, then only processing one queued item at a time for each player and looping continuously to check for new/additional items.

I’m not sure how much delay is involved with either approach or how sensitive you need it to be.

Well if you read some code you can see that it’s an Alert Module. It sends alerts on a player’s screen.

My issue is that this Module queues incorrectly and the queue works for everyone, so for example if you and I where playing my game and suddenly the game alerted everyone that an event was happening, one of us would get it and then after the alert goes away then the other person would get the alert.

The reason why this is an issue is because of the style my game is in and so Players may encounter times where I have to alert them and this issue isn’t ideal what so ever.

I like your suggestions but I would need some guidance on this.

Hmmm, after reading your other replies it seems the problem is due to you waiting for the tween to finish, which is easier to fix.

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()
		end)
	end)
--Moved the check outside of tween.
if #Queue >= 1 then
				task.wait(0.25)
				GUI.Alert(table.unpack(table.remove(Queue, 1)))
else
IsAlerting = false --Moved to else table is empty.
			end

I haven’t tried your script but how I have the tween waiting is what I want. I want 1 alert at a time and if there more it will just queue. But the issue is that the queue is a ‘server queue’ I guess you could say, I want everyone to have there own induvial queue. Is that what your version of my module does?

Ah ok, no sorry, it won’t.

I would move the module to be required by the client.
Fire a remote event from server with the alert info for the client to add to their queue. (So an add to queue function).

Use a second remote to fire to client to call a release function.

Note

It seemed like you wanted to queue alerts then release them at another time, i.e stop/start processing alerts.
If not, then you can process them as received.

The current code will wait for each alert to finish, and as it is on the client will do so separately for each player.