Error when trying to use Instance.new

[Out of registers when trying to allocate 4 registers: exceeded limit 255] is the error I am getting.

This is for a personal practice project of mine. I am designing a program in visual studio that converts an image into a script, which recreates that image with frames. Here is the script my program creates.

1 Like

Well… First of all we need to address your methods…
You do know you can iterate and adjust values to reproduce the same outcome?

What are you trying to do exactly?

Don’t feel like reading all of that.


(Goes on for 257 lines of the same type of text…)

You don’t need to read through it. It’s the same thing but with adjusted properties.

Not really sure what you’re talking about.

This program takes an image the user uploads, and creates a script that creates the image out of Frame objects.

1 Like

I think I might of spotted a typo. Gonna see if that was the problem. If so, I’m dumb lol. Thought the error was something to do with Instance.new being called too many times.

Edit: Nope, was not problem. Wasn’t sure how that didn’t cause an error in the first place though. Weird…

1 Like

No, we need to change how you’re doing it.

What exactly changes on each frame, is it just the position?

1 Like

The color and position.

30 characters

1 Like

Mind showing me a picture of the end product it produces?

1 Like

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