In my popup system, everytime a new popup is added to the player’s screen it’ll tween all the other popups upwards for readability.
script.Parent.PopupFrame.ChildAdded:Connect(function(instance : TextLabel)
for i, popup in pairs(PopupSystem.Notifications) do
if popup ~= instance then
local tween = TweenService:Create(popup, TweenInfo.new(0.5), {Position = popup.Position + UDim2.new(0, 0, -0.08, 0)})
tween:Play()
end
end
end)
However, if two popups are created at the same time, both of them appear at the same position, which is undesired. I was wondering if there was anyway to fix this issue or detect if two children were added at the same time.
You could make it so the added children are added to the beginning of a queue(a fancy way to describe the table we’re using) and then have an iterator run through the rest of the heap. Here’s an example of what I mean:
local queue = {}
script.Parent.PopupFrame.ChildAdded:Connect(function(instance : TextLabel)
table.insert(queue , 1, instance)
for i, popup in ipairs(queue) do
if i <= 1 then continue end
local tween = TweenService:Create(popup, TweenInfo.new(0.5), {Position = popup.Position + UDim2.new(0, 0, -0.08, 0)})
tween:Play()
end
end)