How do you use table.Concat?

Hello, I tried to use table.Concat but it didn’t work and I didn’t get a value. When I print out the table it prints out but when I convert it to a string then it doesn’t work.
table and string printed:
image
code:

for i,v in pairs(inventory) do
		if i == slot then
			print(v)
			local str = table.concat(v)
			print(str)
			return str
		end
	end

Look at the docs.
Table

I looked at that but I still don’t understand it

You’re trying to concat a dictionary, that doesn’t work as it only works for tables, what are you trying to do exactly?

Table.Concat is basically short for string.join()(Used in JavaScript or Java), which is used to join arguments in the table together into a string, sep is the seperator in which that’ll be used like table[iterator]..seperatorhere..table[iterator2]

get the value of v and put it into a string so I can split the value etc

Which value? The key, Apple, or the value of that key, 1? You can only get one or the other or both if you do it twice

Im trying to get the key Apple How can I do this?

I think something like this if each dictionary only has 1 key in it

for i,v in pairs(inventory) do
	if i == slot then
		print(v)
		local str
		for key, value in pairs(v) do
			str = key 
		end
		print(str)
		return str
	end
end
1 Like

Thanks for your help, Now that I look at it, it seems pretty simple, I was just going about it wrong.

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!