Error "attempt to concatenate nil with string"

  1. What do you want to achieve? Keep it simple and clear!
    This a script for an inventory system.

  2. What is the issue? Include screenshots / videos if possible!
    At line 187: invItem.CountDisplay.Text = "<b>" .. toolData.Count .. "x" .. "</b> it is giving me the error “attempt to concatenate nil with string”. I know it is probably something really dumb and obvious, but i am still not very good with scripting and part of this script is from a tutorial.

Here is a screenshot of my Explorer as well with the textbutton i am trying to use called CountDisplay
image

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried googling this error, but i just cant seem to wrap my head around it. I feel it is most likely an error with the way i am trying to get the CountDisplay.
    I have also through the video, and comments just to see if anyone else had ran into this error.
local function UpdatingDisplay()

	--Clearing Out Current Inventory
	removeItems()

	--Getting Inventory Tools
	local invItems = ScanItems()

	for toolName, toolData in pairs(invItems) do

		--Cloning TestItem Sample slot
		local invItem = invSampleItem:Clone()
		invItem.Parent = itemsSF
		invItem.Name = "Item"

		--Setting Display
		invItem.CountDisplay.Text = "<b>" .. toolData.Count .. "x" .. "</b>" <------x Error line
		invItem.Image = toolData.Items[1].TextureId
		invItem.Visible = true
	end

end

This means that toolData.Count is nil, check your code again. If you don’t know why, please send the full code.

The error is self-explanatory. toolData.Count is nil. Try printing toolData and toolData.Count to see what happens.
I suggest this happens because toolData is a dictionary, and it doesn’t have value associated with key Count.

2 Likes

Most definitely because the inventory is empty, toolName and toolData will be nil. You should add some conditions to see if there is any data and name before setting display.

Thank you so much, i feel like such an idiot right now. The issue was when i defined “Count”, i defined it as “count” so my issue was i capitalized the C haha. Like i said in my post, it was probably something really obvious.

Thank you again for giving me the idea of trying to print it. No clue why that flew over my head in the first place.

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