Delay notification of 3 quick events

I have an event that I fire 3 times on the server for each reward a player gets. However, on the client I want these rewards to pop up staggered. so there’s like a second between all 3 appearing.

At the moment, I’ve got the first one appearing, then 2 seconds later the other 2. I’m unsure how to go about staggering the other 2, or if in the future, allowing staggering for several reward notices to appear.

	GameService.Rewards:Connect(function(rewardType, amount, description)
		local NewReward = HUD.Rewards.Prefabs.Template:Clone()

		-- TODO - DELAY HOW LONG BEFORE VISIBLE
		if self.LastRewardNotice + 1 < tick() then -- Make visible instantly
			NewReward.Visible = true
		else
			task.delay(2, function()
				NewReward.Visible = true
			end)
		end

		NewReward.Parent = HUD.Rewards

		self.LastRewardNotice = tick()
	end)

Please don’t suggest I just delay each send on the server, it’s not going to happen. The server needs to send all 3 instantly.

1 Like

If I understand what you’re saying correctly, why not just have a notification framework that can handle those sort of event-based requests?

I agree, he should create a table with all the recieved notifications then handle it somewhere else.

local Time = 0
local Queue = {}

local function PrintMessage()
	Time = os.clock()
	local Message = table.remove(Queue, 1)
	print(Message)
end

local function Notification(Message)
	local Clock = os.clock()
	table.insert(Queue, Message)

	if os.clock() - Time > 2 then
		PrintMessage()
	else
		task.delay(2 * #Queue, PrintMessage)
	end
end