Players.dragon556743.PlayerGui.Notifications.Handle:69: attempt to index nil with 'Lable'

You can write your topic however you want, but you need to answer these questions:

  1. I want to know how to fix this error

  2. When I try to remove a text array from a dictionary it gives me an error

  3. I havent tried much but I’ve tried running it through an if then statement and that didn’t work

If you could help me out that would be great. Thank!
Havent gotten to organizing the script yet sorry :sweat_smile:


local TweenService = game:GetService("TweenService")

local NotificationsInQueue = {}
local ActiveNotifications = 0
local NotificationLimit = 3
local ActiveTime = 6
local QueueNum = #NotificationsInQueue
--local ActiveNotificationNum = #ActiveNotifications

local NotificationBox = script.Parent.Storage:WaitForChild("NotificationBox")
local NotificationSounds = script.Parent:WaitForChild("GUISounds")



local function Push(Lable, Text, Sound)
	task.spawn(function()
			NotificationsInQueue[1] = nil --//issue here//--

		print("yea")

			for _,i in pairs(script.Parent.Holder:GetChildren()) do
				if i:IsA("Frame") then
					i:TweenPosition(UDim2.new(0,0, i.Position.Y.Scale - .300, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad,.3)
		end
	end
		
	local Clone = NotificationBox:Clone()
	ActiveNotifications = ActiveNotifications + 1
	task.wait(.7)
	Clone.Parent = script.Parent.Holder
	Clone.Lable.Text = Lable
	Clone.Text.Text = Text
		Clone:TweenPosition(UDim2.new(0,0, Clone.Position.Y.Scale, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad,.3)
		
		if Sound == "None" then
			NotificationSounds.none:Play()
		elseif Sound == "Error" then
			NotificationSounds.error:Play()
		elseif Sound == "Blop" then
			NotificationSounds.blop:Play()
		end
		
			task.spawn(function()
				task.wait(.3)
	
		
				task.wait(ActiveTime)

				Clone:TweenPosition(UDim2.new(1,0, Clone.Position.Y.Scale, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad,.3)
				task.wait(1)
				ActiveNotifications = ActiveNotifications - 1
				Clone:Destroy()
		end)
	end)
end

local function FireNotification(Lable, Text, Sound)
	print("yea")
	table.insert(NotificationsInQueue,{["Queue"] = #NotificationsInQueue+1,["Lable"] = Lable; ["Text"] = Text; ["Sound"] = Sound})
	print("yea")
end



local function Update()
	if ActiveNotifications < NotificationLimit and #NotificationsInQueue > 0 then
		Push(NotificationsInQueue[1].Lable, NotificationsInQueue[1].Text, NotificationsInQueue[1].Sound)
			for i, v in pairs(NotificationsInQueue) do
				v["Queue"] -= 1
		end
	end
end

task.spawn(function()
	while task.wait(1.40) do
	Update()
	end
end)

Thanks!

1 Like

Put quotes around lable like this: “Lable.” Also, it’s spelled label.

Hi, What is on line 69, I’m sure you have looked already?

I didn’t even realize I spelt that wrong. :sweat_smile: Anyways I’m not entirely sure where u want me to put the quotes.

Here you go sorry I forgot to include that.

Pretty sure NotificationsInQueue[1] returns nil, can you check?

Just ran it and it returned “attempt to index nil with ‘Label’” Is that what you needed?

No, the line above the one you sent, (68) - can you print(NotificationsInQueue[1]) before that, and see if it prints nil?

Ah ok I get what you mean, yes it did return nil.

Yea have you made sanity check, to check if the table (NotificationsInQueue) is empty, before trying to get the first value?

Yes but here I am seeing if the queue is over 0. Should I change it so it checks if the queue equals 0?

Uhm, if it’s not empty, try and print; print(NotificationsInQueue)

It should print whatever is in there

It returned the first one in the queue saying “Void” and all the others normal.
image

Well that is one step closer. Now next step is to figure out, why is only the first one containing void?

Ok it starts out in “Update” then moves onto “Push” that’s where I’m thinking the problem lays.


Try not to spawn a new task when you put [1] in nil state.

Nope still the same error. Hmmm

Can I ask what your use-case is, because I have made something similar, with putting notifications in queue.

It will be fired from a Bindable Event sending a request to


From there storing it in queue no matter if the “ActiveNotifications” is empty.
If its empty the update function will sent it to the push Function

Which sends it out to the player


Phew

Here is a achievement queue I made some time ago, I’ve removed most of the unneccessary stuff.

local GrantedQueue = {}
local GrantedQueueInProgress = false
local function AchievementGranted(AchievementName, AchievementLevel)
	if not AchievementName or not AchievementLevel then return end
	local DisplayName = AchievementData_MS.DisplayNames[AchievementName][AchievementLevel] 
	if not DisplayName then return end
	
	GrantedQueue[DisplayName] = true -- Puts the new achievement into the queue
	if not GrantedQueueInProgress then -- Starts the queue if it is not already in progress
		GrantedQueueInProgress = true
		for DisplayName, _ in pairs(GrantedQueue) do
			local NewAchievementFrame = AchievementFrameTemplate:Clone()
			NewAchievementFrame.LayoutOrder = tick()
			NewAchievementFrame.Parent = Gui.Frame
			task.wait(3.5)
			NewAchievementFrame:Destroy()
			GrantedQueue[DisplayName] = nil
		end
		GrantedQueueInProgress = false
	end
end

local function Intialize(Child)
	Child:GetAttributeChangedSignal("Level"):Connect(function()
		local AchievementName = Child.Name
		local AchievementLevel = Child:GetAttribute("Level")
		AchievementGranted(AchievementName, AchievementLevel)
	end)
	local AchievementName = Child.Name
	local AchievementLevel = Child:GetAttribute("Level")
	AchievementGranted(AchievementName, AchievementLevel)
end

Achievements.ChildAdded:Connect(function(Child)
	Intialize(Child)
end)

for _, Child in pairs(Achievements:GetChildren()) do
	Intialize(Child)
end

I don’t know if that kind of queue system can help you out.