Error when trying to use Instance.new

It doesn’t produce anything, because of the error I posted. :frowning:

1 Like
local IMG2RBX = Instance.new("ScreenGui",game.Players.LocalPlayer.PlayerGui)
for i = 1, 256 do
local newFrame = Instance.new("Frame", IMG2RBX);
newFrame.BorderSizePixel = 0;
newFrame.BackgroundColor3 = Color3.fromRGB(255,255,255);
newFrame.Size = UDim2.new(0,1,0,1);
newFrame.Position = UDim2.new(0, 0, 0, 0);
wait()
end

You have too much local variables. Use a for loop.

1 Like

I would of never guessed that. I’ll try that, thanks.

1 Like

You still need to edit the position and color. :stuck_out_tongue:

Hence why i’m trying to ask you what it’s supposed to look like.

1 Like

I get the color and position automatically by each pixel in the image. My C# code handles that.

1 Like

Oh ok, so pull that data from the array for each frame then put it into the pos/color in the loop.

1 Like

Yep, that’s what I’ve been doing. You can see it in the code I posted

1 Like

Do you need help setting up the array or figuring out how to connect it in the loop?

1 Like

Wait there is a problem. I need to create a new frame for every pixel in the image… I don’t see how I can dynamically change the position and color when it’s in a for loop like posted above.

1 Like

Get an array with color/pos and tie it into the loop.

Use the key for the tile layout.

1 Like

Maybe a function will work? function creates local frame, returns it, then the code sets the properties

1 Like

Function or no function, works the same way. You’ll need to make an array.

1 Like

PosAndColor = {
{colorvalue, posvalue},
{colorvalue, posvalue},
{colorvalue, posvalue},
}

If the positions just make a shape you can use math to get rid of that issue or use a UIGridLayout and number the order they go in based off the key of the main array; however, the gridlayout can mess up the image.

1 Like

Tell me the resolution of the image like 20 pixels by 20 pixels then we can go from there and then make a color array for each cube.

1 Like

I was able to fix it. Here is the end result. https://i.imgur.com/R9ol11P.png

This is what my program looks like. https://i.imgur.com/9THlkt3.png

1 Like

You really should change it to a loop and just have an array for colors and pixel size x pixel size.

1 Like

Yeah I’ll reprogram it later to do that.

1 Like

Yeah. The issue here is an excess of local variables, not Instance.new. There’s a 200 local variable limit if I recall correctly. A few optimisations have already been recommended above, so I won’t repeat them.

1 Like

Really? You have any more information on this?

I’ve been programming for almost 10 years now and I’ve never came across a 200 local variable limit. That being said. :thinking: I’m not sure if I even reached 200 before.

1 Like

I don’t quite have any information, but you can test for this yourself.

Spam this in your code around 41 or more times:

local a = 1
local a = 1
local a = 1
local a = 1
local a = 1

And you get:

Not quite the same error as the OP but I have a feeling like they’re related. The original code absolutely abuses and hard codes a colossal amount of local variables.

The local variable limit is imposed by the Lua VM.

Whole discussion you can follow from some years ago:

2 Likes