"Out of registers when trying to allocate 4 registers: exceeded limit 255" What does it mean?


After adding about 10 new GuiObjects, this error started popping up. My first guess when I saw it output “Out of registers” was that I somehow ran out of memory, but my memory usage was not even at 300MB, so I’m left clueless as to what this error is suggesting.

I saw someone ran into this error here and it was related to the new virtual machine. Apparently it has been fixed, but this is not the case for me.

Is there a limit to how many GuiObjects there can be in one place?

2 Likes

Can you show what your code looks like? This sounds like you might have too many local variables while adding a loop, function call, or something to the code.

1 Like

I do have a lot of local variables. About 500 lines of assigning variables manually, and then loops assign a bunch more variables.

This is the latest function I added before the error started happening:

local function updateLeaderboards(leaderboardInfoTable)
	local blocksMinedTable = leaderboardInfoTable[1]
	local coinsTable = leaderboardInfoTable[2]
	if blocksMinedTable and coinsTable then
		for i,v in pairs(leaderboardBlocksMinedFrame:GetChildren()) do
			if v.Name ~= "UIListLayout" then
				v:Destroy()
			end
		end
		for i,v in pairs(leaderboardCoinsFrame:GetChildren()) do
			if v.Name ~= "UIListLayout" then
				v:Destroy()
			end
		end
		for iteration = 1, 2 do
			for i = 1, 10 do
				local infoTable
				if iteration == 1 then
					infoTable = blocksMinedTable[i]
				elseif iteration == 2 then
					infoTable = coinsTable[i]
				end
				if infoTable then
					coroutine.resume(coroutine.create(function()
						local plrId = infoTable[1]
						local value = infoTable[2]
						local newFrame = leaderboardTemplate:Clone()
						local plrImage
						local plrName
						pcall(function()
							plrName = ps:GetNameFromUserIdAsync(plrId)
						end)
						pcall(function()
							plrImage = ps:GetUserThumbnailAsync(plrId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size352x352)
						end)
						if not plrName then
							plrName = "Couldn't load!"
						end
									
						newFrame.Name = alphabet[i]..plrName
						newFrame.PlayerName.T.Text = plrName
						newFrame.PlayerImage.Image = plrImage or "rbxassetid://4675020175"
						newFrame.InfoFrame.Amount.Text = value
						if iteration == 1 then
							newFrame.InfoFrame.Title.Text = "Lifetime Blocks Mined:"
							newFrame.TypeImage.Image = "rbxgameasset://Images/cube"
						elseif iteration == 2 then
							newFrame.InfoFrame.Title.Text = "Lifetime Coins Acquired:"
							newFrame.TypeImage.Image = "rbxgameasset://Images/crown-coin (1)"
						end
						if i == 1 then
							newFrame.CrownImage.Image = "rbxassetid://4871959113"
							newFrame.CrownImage.ImageTransparency = 0
						elseif i == 2 then
							newFrame.CrownImage.Image = "rbxassetid://4871958921"
							newFrame.CrownImage.ImageTransparency = 0
						elseif i == 3 then
							newFrame.CrownImage.Image = "rbxassetid://4871959005"
							newFrame.CrownImage.ImageTransparency = 0
						end
						newFrame.Visible = true
						if iteration == 1 then
							newFrame.Parent = leaderboardBlocksMinedFrame
						elseif iteration == 2 then
							newFrame.Parent = leaderboardCoinsFrame
						end
					end))
				else
					break
				end
				wait()
			end
		end
	end
end

This particular function executes every time the user opens their menu. There is however a 60 second cooldown.

1 Like

If you can share the entire script (feel free to send it in a PM) that would be great - it could be some edge case in the Lua compiler where we aren’t optimally allocating the registers for variables, or it could be an issue in the script, but regardless we will need to at least improve the error message emitted here.

2 Likes

The issue has been solved in PMs. I was using too many local variables. The output message has also been changed.

3 Likes

Ty, In case this happens to anyone else I leave this code that can fix these errors (I recommend having a copy that is well because this will mark everything with warn):

local Use = game.StarterGui.LocalScript -- Change this to the original path

local A = Use:Clone()
A.Name = Use.Name.."_Original"
A.Parent = Use.Parent

local ToFind = "local%s+([%w_]+)%s*=%s*" 
local Mod = (Use.Source):gsub(ToFind, function(match) 
	return match:match(ToFind) or match.." = " 
end) 
Use.Source = Mod