Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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

Log in to vote
1
Answered by 8 years ago

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
1
`#tab >= 1` or `#tab > 0`, NOT  `#tab > 1`, to tell if something is not empty. BlueTaslem 18071 — 8y
0
I changed it, thanks aquathorn321 858 — 8y
Ad

Answer this question