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

How do you get the number from a :GetChildren()?

Using a

local chars = items:GetChildren()
for i = 1, #chars do

How would I make it create a new value with the name being the number of the "i"?

1 answer

✓ Accepted answer

You could use the _G function to accomplish that.

local chars = items:GetChildren()
for i,v in pairs(chars) do
	_G["Item" .. i] = "foobar"
end

I also changed the for loop so it's a bit better (i would say). You can use v to reference the object that has been indexed by the i value, basically the object is chars[i].

You can then use this little bit of code to reference that value.

print(_G["Item" .. 1])

output:

foobar

The _G function is global so all scripts can access it.

3 comments

1

Thank you for answering and going into detail on what everything means!

0

this is big bad dont do

0

_G isn't a function, its a table.

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