Notification system with a bug

I have a notification system which works fine, except one issue which is that the first notification will never go away and it will keep covering other new notifications.

I have tried lots of research and haven’t gotten anything better. This is the last option I can think of

Here is the code, its a module script:

local plr = game.Players.LocalPlayer
wait(1)
local UI = plr:WaitForChild("PlayerGui"):WaitForChild("NotificationGui")
local TS = game:GetService("TweenService")
local DS = game:GetService("Debris")
local RS = game:GetService("ReplicatedStorage")

local frame = RS:WaitForChild("NotificationFrame")
local msg1 = UI:WaitForChild("MessageOne")
local msg2 = UI:WaitForChild("MessageTwo")

local module = {}

module.Positions = {
	Pos1 = {
		Size = UDim2.new(0.193,0,0.08,0),
		Position = UDim2.new(0.786,0,0.736,0)
	},
	Pos2 = {
		Size = UDim2.new(0.157,0,0.065,0),
		Position = UDim2.new(0.8,0,0.836,0)
	}
}

module.SendMessage = function(Message,skip)
	if Message then
		if msg2.Value then
			local frame3 = UI:FindFirstChild("NotificationFrame2")
			if frame3 then
				frame3.Name = "NotificationFrame3"
				local tween = TS:Create(frame3,TweenInfo.new(0.2,Enum.EasingStyle.Linear),{Position = UDim2.new(0.909,0,1.2,0)})
				tween:Play()
				DS:AddItem(frame3, 0.3)
			end
		end
		if msg1.Value then
			msg2.Value = msg1.Value
			local frame2 = UI:FindFirstChild("NotificationFrame1")
			if frame2 then
				frame2.Name = "NotificationFrame2"
				local tween = TS:Create(frame2, TweenInfo.new(0.2,Enum.EasingStyle.Linear),module.Positions.Pos2)
				tween:Play()
			end
		end
		if not skip then
			local frame1 = frame:Clone()
			frame1.Parent = UI
			frame.Name = "NotificationFrame1"
			frame1:WaitForChild("Main"):WaitForChild("Text").Text = Message
			frame1.Position = UDim2.new(1.2,0,0.826,0)
			local tween = TS:Create(frame1,TweenInfo.new(0.2,Enum.EasingStyle.Linear),module.Positions.Pos1)
			tween:Play()
			wait(1)
			if frame1.Parent then
				module.SendMessage(true,true)
			end
			wait(0.5)
			if frame1.Parent then
				module.SendMessage(true,true)
			end
		end
	end
end

return module

If you can help that’ll be greatly appreciated but when you do explain how you fixed it so I can learn and know for next time

Maybe try caching?

local activeFrame = nil

Example:

local plr = game.Players.LocalPlayer
wait(1)
local UI = plr:WaitForChild("PlayerGui"):WaitForChild("NotificationGui")
local TS = game:GetService("TweenService")
local DS = game:GetService("Debris")
local RS = game:GetService("ReplicatedStorage")

local frame = RS:WaitForChild("NotificationFrame")
local msg1 = UI:WaitForChild("MessageOne")
local msg2 = UI:WaitForChild("MessageTwo")

local module = {}
module.Positions = {
	Pos1 = {
		Size = UDim2.new(0.193, 0, 0.08, 0),
		Position = UDim2.new(0.786, 0, 0.736, 0)
	},
	Pos2 = {
		Size = UDim2.new(0.157, 0, 0.065, 0),
		Position = UDim2.new(0.8, 0, 0.836, 0)
	}
}

local activeFrame = nil

module.SendMessage = function(Message, skip)
	if Message then
		if activeFrame then
			activeFrame:Destroy()
		end

		activeFrame = frame:Clone()
		activeFrame.Parent = UI
		activeFrame.Name = "NotificationFrame1"
		activeFrame:WaitForChild("Main"):WaitForChild("Text").Text = Message
		activeFrame.Position = UDim2.new(1.2, 0, 0.826, 0)
		local tween = TS:Create(activeFrame, TweenInfo.new(0.2, Enum.EasingStyle.Linear), module.Positions.Pos1)
		tween:Play()
		wait(1)

		if activeFrame.Parent then
			activeFrame:Destroy()
			activeFrame = nil
		end
	end
end

return module

Explanation:

There’s a problem with this approach because it can lead to an infinite loop if the first notification is not properly removed.

I think that could probably work, although my system holds two notifications on screen at once (that’s why the frame gets named 1, 2 then 3 for each stage.

I can send a recording if needed

Please give it a try and inform me about its functionality. Feel free to make any necessary modifications to exclude the frame:Destroy() function.

ok, so I think this is getting somewhere The only error that came was:
attempt to index nil with ‘Parent’
at the if statement of if active frame has a parent

It came after the third try, and the a notification did come before the old one disappeared

So what is exactly you’re issue now?

Ah sorry. You can try these solutions.

if activeFrame and activeFrame.Parent then
	activeFrame:Destroy()
	activeFrame = nil
end
if activeFrame and activeFrame.Parent then
if activeFrame.Parent then

Lol sorry, you didnt understand my message bc I had a major typo although I edited my message. I will test this now

It works! Thank you so much! (extra chars)

No problem! Please solution :smiley:

(charssss)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.