I wrote a basic notification system for my game recently and the fundamentals work nicely. The notification is played, and then it moves off of the screen and disappears for good. That’s how it’s supposed to work, right?
Apparently not, because there seems to be a bit of a vulnerability that I’ve been battling for the last week.
If you try to activate a notification as another one is leaving, the script errors, breaking it permanently. There’s no way of fixing it from there.
Photo of error given:
Video demo attached below:
EDIT: when clicking on this link, the video is downloaded to your device. It was uploaded to Streamable, and I am not sure I can fix this.
External MediaEverything is explained within the clip, so please watch it before making a statement.
If the script is needed, here (it is a LocalScript):
local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local TweenService = game:GetService("TweenService")
local NotificationEvent = game:GetService("ReplicatedStorage"):WaitForChild("Notification")
local NotificationGui = script.NotificationGui
local Active = script.ActiveNotifications
local notificationguis = {}
local TweenInf = TweenInfo.new(
0.6,
Enum.EasingStyle.Back,
Enum.EasingDirection.Out,
0,
false
)
local TweenInf2 = TweenInfo.new(
0.5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.In,
0,
false
)
local TweenInf3 = TweenInfo.new(
0.5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false
)
NotificationEvent.OnClientEvent:Connect(function(label, text)
local gui = NotificationGui:Clone()
gui.Parent = PlayerGui
table.insert(notificationguis,gui)
if Active.Value >=1 then
for _,ui in notificationguis do
TweenService:Create(ui.notification, TweenInf3, {Position = UDim2.new(ui.notification.Position.X.Scale, 0, ui.notification.Position.Y.Scale-0.18, 0)}):Play() -- This is the line the error always falls back to, no matter what in the script that I try to change.
end
end
Active.Value = Active.Value+1
TweenService:Create(gui.notification, TweenInf, {Position = UDim2.new(1,0,0.9,0)}):Play()
workspace.GlobalAudios.Misc.Notification:Play()
gui.notification.notificationlabel.Text = label
gui.notification.contents.notificationtext.Text = text
task.wait(8)
print(notificationguis)
TweenService:Create(gui.notification, TweenInf2, {Position = UDim2.new(1.35,0,gui.notification.Position.Y.Scale,0)}):Play()
task.wait(0.5)
gui:Destroy()
gui = nil
table.remove(notificationguis,Active.Value)
Active.Value = Active.Value-1
end)
Line 41, the line the error always falls back to, has been labeled.
How can I prevent this error from reoccurring when this system goes live in my game’s next update?