Keep table in order from script?

I’m making a keybind system and I’m working on the keybinds gui. I heard that to get it in order as defined in the script, I have to use ipairs, but when I use ipairs, it just doesn’t run at all? Anyone know how to fix this or other ways?

for name, key in ipairs(keybindsData.current) do
		local frame = content.Item:Clone()
		frame.Visible = true
		
		local nameLabel = frame:FindFirstChild("Name")
		
		if nameLabel then
			nameLabel.Text = tostring(name)
		end
		
		local keyButton = frame:FindFirstChild("Keybind")
		
		if keyButton then
			keyButton.Text = tostring(key.Name)
		end
		
		frame.Parent = content
	end

KEYBINDS TABLE:

["Rotate Mode"] = Enum.KeyCode.LeftControl,
["Dribble"] = Enum.KeyCode.One,
["Pass"] = Enum.KeyCode.Two,
["Shoot"] = Enum.KeyCode.Three,
["Ping"] = Enum.KeyCode.Q,
["BallCamera"] = Enum.KeyCode.Backspace,

ipairs only works in numerically assigned table values (arrays), not dictionaries. You can use ipairs on an array then get the information you need from another table.

1 Like

You’d have to redo your table if you want to use ipairs. Something like this:

local KeyBinds = {
{Name = "Pass",  KeyBind = Enum.KeyCode.Two},
...
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.