Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to check if there's any value's in a table?

Can anyone tell me if there is any-way to check if there are any value's in a table? I tried string.len but it give's bad argument #1 to 'len' (string expected, got table) error.

Script:

local TestingTable = {}

for _,v in pairs(script.Parent:GetChildren()) do
	table.insert(TestingTable,v.Name)
	print("Added "..v.Name)
end


while wait() do
	if string.len(TestingTable) > 1 then -- This is the part I need help with
		local testing = script.Parent:FindFirstChild(TestingTable[1])
		table.remove(TestingTable,1)
	end
end

Any help appreciated.

1 answer

✓ Accepted answer

You can find the length of a table by placing a hashtag before it in a script. For example:

local tab = {1, "two", "3"}

print(#tab) --Prints 3, the amount of values stored in the table.

You can then integrate this into your script like so:

if #TestingTable > 0 then
--execute code
end

2 comments

1

#tab >= 1 or #tab > 0, NOT  #tab > 1, to tell if something is not empty.

0

I changed it, thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.