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"?
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.