How To Know How Many Objects Are In A Table

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I’m trying to make a Plugin to weld things (I know there’s a bunch of them, but I need it) and I need to make sure the Player chooses only one part as the main part

  1. What is the issue? Include screenshots / videos if possible!

As selection returns a table, i need to know how many objects are in a table, if it’s one then it’ll be the main part, if there’s more than one it’ll throw a warning

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Checked DevForum, couldn’t find anything

My code isn’t important, but if you need it just ask

I only need to know how to know how many objects are in stable, thanks in advance!

(I know taht I used teh classic help format, too lazy to edit it right now)

Do you mean using #table ??

Or loop and get each object

You can do this #table it shows how many there is, or do this

for i, v in table do
   print(i)
end

#table is all you need, as @NDavis06 said.
To avoid the warning, just do

if #table == 1 then return end

I need to know the number, and I totally forgot about the # operator, I’ll try that ASAP

No really I need it to make sure the person only chooses one object, thanks for your help!

Sorry I misread, just change it from == to ~=.

1 Like