I’m trying to make a notification system for something I’m working on, my goal is to make the notifications correctly move upwards when a new notification arrives but the current script I made doesn’t work properly, it only moves an existing frame in the way of the new frame upwards but doesn’t after, also there is no gap between the notifications but that’s probably due to the way I told it to move the frames.
local function Tween(obj, time, sty, dir, goal)
tweenService:Create(obj, TweenInfo.new(time, sty, dir), goal):Play()
end
local UI = currentUI
for _,v in ipairs(Screen:GetChildren()) do
if v:IsA("Frame") and v.Name == "Notification" then
local frameYPos = v.Position.Y.Scale + v.Size.Y.Scale
local startPos = v.Position
local endpos = startPos - UDim2.new(0, 0, frameYPos - UI.Position.Y.Scale, 0)
Tween(v, 0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, {Position = endpos})
end
end
UI.Parent = Screen
UI.Visible = true
How would i make the frames correctly move themselves upwards for the new notification to have room? Also if you get a solution can you please explain to me how you did it.
basically its goes upwards and when a certain amount of notifications are on screen then the oldest notification will go off screen and the next notification will move into place.
You’ll have to specify a number for how many notifications can be on screen at once. You could count the number of notification frames inside the GUI element, and next time a notification pops up, get the number of elements and move the oldest one off the screen.
I only want about 4 notifications on at once as a limit to how many notifications are on the screen at once. I should know how to count the notifications by using a for loop and checking if they are notifications then getting the oldest out of them.
Might want to check how you manage tweens, you should destroy them after you’re done with them.
Like GFink said, you should specify the maximum number of notifications on the screen at once. You can use a for loop to move all the notification frames up by one step (however big they are + padding), and tweening the oldest one out of view & destroying it when that number is reached. You can do this by either looking at how many children there are in the frame that contains these notifications, or by using a counter in the for loop.
local function Tween(obj, time, sty, dir, goal)
local tween = tweenService:Create(obj, TweenInfo.new(time, sty, dir), goal)
tween:Play()
tween.Completed:Connect(function()
tween:Destroy()
end)
end
local UI = currentUI
local padding = 2
local maxNotifs = 4
for _,notif in ipairs(Screen:GetChildren()) do
if notif:IsA("Frame") and notif.Name == "Notification" then
local frameYPos = notif.Position.Y.Scale + notif.Size.Y.Scale
local endPos = notif.Position - UDim2.new(0,0, frameYPos - (UI.Position.Y.Scale + padding), 0)
Tween(notif, 0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, {Position = endpos}
end
end
The script was functionall but the notifications went downwards instead so i changed the padding from a “+ padding” to a “- padding” which seemed to have worked and made the notifications go upwards. Also having the padding at 2 was really high for me and the ui’s just flew upwards off screen so i changed it to 0.03 which worked. The only problem is still that none of the other UI’s are moving afterwards and im trying to figure out why.
Sorry, I was working in terms of pixels with the padding.
Completely forgot to fix that bug too. I’d use the offsets (pixels) instead of scale, it just works easier with this stuff.
I might not be able to help you past this, sorry. It’s midnight and I’m trying to work on my own game too. I hope I could be of good use though!
thanks for the help, the script you provided made it easier for me to work with the tweening
also forgot to mention u missed a parenthesis at the end of the tween func, ill post the fixed variant here.
local function Tween(obj, time, sty, dir, goal)
local tween = tweenService:Create(obj, TweenInfo.new(time, sty, dir), goal)
tween:Play()
tween.Completed:Connect(function()
tween:Destroy()
end)
end
local UI = currentUI
local padding = 0.03
local maxNotifs = 4
for _,notif in ipairs(Screen:GetChildren()) do
if notif:IsA("Frame") and notif.Name == "Notification" then
local frameYPos = notif.Position.Y.Scale + notif.Size.Y.Scale
local endPos = notif.Position - UDim2.new(0,0, frameYPos - (UI.Position.Y.Scale - padding), 0)
Tween(notif, 0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, {Position = endPos})
end
end
All i need help with is the notifications not tweening upwards now and then i can do the rest myself.