Trouble with i,v in pairs loop

Hello,

I’m making a POS system for a restaurant in one of my games, and I’m trying to create a method to generate buttons automatically with the correct text. I’m using a dictionary to define all the possible buttons, and a pairs loop to generate the correct number of buttons and assign the text to each button from the dictionary.

The issue I’m having is that there is an empty button that is generated at the start, despite the list starting with “Breakfast”, and obviously I don’t want this to be here. I’ve tried to search for a solution but I’m unable to find one that is close or relevant to the issue.

Here is the loop in question:

for i,v in pairs(Hotkeys) do
	local FindGrid = Screen.Main.Screen3.Main.Bottom:FindFirstChild("UIGridLayout")
	if FindGrid == nil then -- Checks to see if UIGridLayout is present in Button area
		local GridLayout = Screen.Main.Screen3.Main.BottomTemplate.UIGridLayout:Clone()
		GridLayout.Parent = Screen.Main.Screen3.Main.Bottom
	end		
	-- Clone template button and create new one with entry from the dictionary
	local NewButton = Screen.Main.Screen3.Main.BottomTemplate.btn_F1:Clone()
	NewButton.Parent = Screen.Main.Screen3.Main.Bottom
	NewButton.Name = "btn_F".. tostring(Buttons)
	NewButton.Text = i
	print(i)		
end

And here is the dictionary it is referencing

Cafe_Hotkeys = {
	["Breakfast"] = {},
	["Hot Food"] = {},
	["Hot Drinks"] = {},
	["Cold Drinks"] = {},
	["Sandwiches"] = {},
},

Any help is greatly appreciated

Is it possible that there’s already a button there from cloning the whole screen template, before you start adding them?

Ah that’s why, I probably should have checked that before lol. Thanks for your help :slight_smile: