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

Comparing a table with a number error?

Asked by 9 years ago
if script.Dueling:GetChildren() <= 1 then
    print("1")
end

trying to compare a table with a number How is it a table? Dueling is just a folder inside the script.

1 answer

Log in to vote
0
Answered by 9 years ago

You're using GetChildren, which returns all the children of the parent (in your case, the Dueling folder) in an array, which is a type of table. This is why you're getting the error that you're comparing a number to a table.

I'm not sure exactly what you're trying to do so I'm assuming you're trying to check if the amount of children in the Dueling folder is under or equal to one.

Just add a # at the start of script.Dueling. The # operator gets the length of the table and returns it. The length of a table is a number, so you shouldn't run into any errors when comparing it.

if #script.Dueling:GetChildren() <= 1 then --Checks if the length of the GetChildren table with all of the Dueling folder's children in it is under or equal to 1.
    print("1")
end

I hope my answer helped you. If it did, be sure to accept it.

Ad

Answer this question