Lua won't let me find length of 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!

Find the length of a table without this happening /

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

image
image

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

I have tried to look for solutions and haven’t found one yet

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

for i in NumberRange(1, #Keys) do
	local clonedObject = clone:Clone()
	clone.Parent = Keys[i]
	clone.Run.Enabled = true
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

EDIT There’s nothing wrong with the table in question if you were going to say that, it simply uses the GetChildren method.

3 Likes

Instead of

for I 

Do this:

for i,_ 

Maybe that will fix the error

2 Likes

I’m going to try that tomorrow, it’s late now for me.

2 Likes

You can’t iterate over a NumberRange value. This will give you the result you’re wanting:

for i = 1, #Keys do
    local clonedObject = clone:Clone()
	clone.Parent = Keys[i]
	clone.Run.Enabled = true
end
2 Likes

You need to make sure that you one, use a basic for loop, and two
it should be “clonedObject” not “clone” or it would be passing in only one of whatever you wanted to clone.

for i = 1, #Keys do
    local clonedObject = clone:Clone()
	 clonedObject.Parent = Keys[i]
	 clonedObject.Run.Enabled = true
end
2 Likes

Hey OP, just letting you know that this could possibly be AI-generated code - the things that throw me off are the weird reference to a Run property (which no Instance has as a property, if I’m not mistaken) (if it was an attribute you’d use the set attribute method) and the incorrect use of the NumberRange object.

If it was your doing, it’s usually not a good idea to trust AI-generated code, especially for an IDE with a unique language such as ROBLOX. Instead, use references to the documentation or the DevForum in order to figure out how and why things work.

2 Likes

Run is a script, so it has to be enabled after the object gets cloned. Also, I’m not too experienced with for loops because sometimes I do python and for that, the for loop is structured:

for i in range(0, 10):
   #somecode

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.