Attempt to perform arithmetic (sub) on table and number

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

  1. I would like to know what’s causing this error.

  1. One thing I’ve tried is (If v ~= nil then
    else
    “Code would be here”
    end)

But when I’ve tried this the Update function doesn’t remove the queuing notification form the queue table.

If you can help me that would be greatly appreciated, Thanks!

(Sorry if this code is messy havent organized it yet :sweat_smile:)


local TweenService = game:GetService("TweenService")

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

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



--//Pushes the notification out
local function Push(Lable, Text, Sound)
	task.spawn(function()
		table.remove(NotificationsInQueue[1])
		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

--//Puts notification into queue
local function FireNotification(Lable, Text, Sound)
	print("yea")
	table.insert(NotificationsInQueue,{#NotificationsInQueue+1,["Lable"] = Lable; ["Text"] = Text; ["Sound"] = Sound})
	print("yea")
end


--//Error is happening here
local function Update()
	if ActiveNotifications < NotificationLimit and #NotificationsInQueue > 0 then
		Push(NotificationsInQueue[1].Lable, NotificationsInQueue[1].Text, NotificationsInQueue[1].Sound)
		task.wait()
			for i, v in pairs(NotificationsInQueue) do
				v = v - 1
		end
	end
end

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

Feel free to ask me any further questions. Thanks again.

1 Like

Looks like NotificationsInQueue is a table, meaning when you’re looping through it you’re trying to do {...} - 1 rather than ["Queue"] - 1

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

for i, v in pairs(NotificationsInQueue) do
    --you are trying to subtract {} - 1
	--v = v - 1

   --this should work instead
    v[1] -= 1
end

Thanks, the first one work the edit didn’t. It works now! I know my topic was only about the error perhaps do you know why its not Removing “NotificationsInQueue[1]” from the table because it keeps repeating my test notifications.

Where is the code relating to that?

Here it is. There’s a high chance this isn’t the cause of it though.

Try doing this

NotificationsInQueue[1] = nil

Currently in Roblox, table.remove takes in 2 arguments, the second being the location in the table. Also seeing that this is a dictionary, you shouldn’t be using table commands on it.

When I did that an error popped up.