Note: This is in Roblox's version of Lua. I have the following snippet of code:
for index, child in pairs(workspace.IMG:GetChildren()) do
xyz = child.Position
ImgScript = {}
table.insert(ImgScript, -1, child.BrickColor.Number, xyz.X, xyz.Y, xyz.Z)
end
So workspace.IMG is a model that has a bunch of bricks in it. I am trying to turn that model into a script for script builder. So I could make it do Instance.new('Part', script) blah blah blah for every brick, but that amounts to a large script. So instead I am making a table that has all of the necessary information (BrickColor and Position). Here is what I want the table to look like:
{{BrickColor Number, X, Y, Z}, {123, 14, 52, 65}, {156, 13, 52, 65}, etc.}
But the script I currently have doesn't make this kind of table. It doesn't do anything; In fact, I don't expect it to do what I am asking; I just don't know how to make it make this kind of table.
Put that line
ImgScript = {}
before the loop. As it is, you're creating a new table (and discarding the previous one) on each iteration.
If you want the ImgScript table to start with the 'header' entry, add it there.
And, of course, the table.insert call should be
table.insert(ImgScript, {child.BrickColor.Number, xyz.X, xyz.Y, xyz.Z})
In the end, the whole script would be:
ImgScript = {{'BrickColor Number', 'X', 'Y', 'Z'}}
for index, child in pairs(workspace.IMG:GetChildren()) do
local xyz = child.Position
table.insert(ImgScript, {child.BrickColor.Number, xyz.X, xyz.Y, xyz.Z})
end
I think you want this:
ImgScript = {}
for index, child in pairs(workspace.IMG:GetChildren()) do
xyz = child.Position
table.insert(ImgScript,{child.BrickColor.Number, xyz.X, xyz.Y, xyz.Z})
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With