How to loop through a table inside a dictonary?

hello im not sure of how to loop through a table inside a dictonary. This is my current code:


local Sides = {
	SideOne = {UDim2.new(0.232, 0,0.264, 0), UDim2.new(0.232, 0,0.471, 0), UDim2.new(0.232, 0,0.681, 0)},
	SideTwo = {UDim2.new(0.345, 0,0.264, 0), UDim2.new(0.345, 0,0.471, 0), UDim2.new(0.345, 0,0.681, 0)},
	SideThree = {UDim2.new(0.456, 0,0.264, 0), UDim2.new(0.456, 0,0.47, 0), UDim2.new(0.456, 0,0.686, 0)},
	SideFour = {UDim2.new(0.566, 0,0.264, 0), UDim2.new(0.566, 0,0.471, 0), UDim2.new(0.566, 0,0.681, 0)},
	sidefive = {UDim2.new(0.681, 0,0.264, 0), UDim2.new(0.681, 0,0.471, 0), UDim2.new(0.68, 0,0.681, 0)}
}

for i,v in pairs(Sides) do
for i,v in pairs(v) do
print(v)
end
end

but this doesn’t work. any help would help

You are assigning a variable with the same name. I suggest renaming them.

how do i loop through the table inside the dictonary?

You don’t have to loop through a dictionary you can just index it by doing Sides.SideOne

1 Like

Does ipairs do anything different?

i want to go through every single one not just one of the tables

Then it should work the same as looping through a table

local Sides = {
	SideOne = {UDim2.new(0.232, 0,0.264, 0), UDim2.new(0.232, 0,0.471, 0), UDim2.new(0.232, 0,0.681, 0)},
	SideTwo = {UDim2.new(0.345, 0,0.264, 0), UDim2.new(0.345, 0,0.471, 0), UDim2.new(0.345, 0,0.681, 0)},
	SideThree = {UDim2.new(0.456, 0,0.264, 0), UDim2.new(0.456, 0,0.47, 0), UDim2.new(0.456, 0,0.686, 0)},
	SideFour = {UDim2.new(0.566, 0,0.264, 0), UDim2.new(0.566, 0,0.471, 0), UDim2.new(0.566, 0,0.681, 0)},
	sidefive = {UDim2.new(0.681, 0,0.264, 0), UDim2.new(0.681, 0,0.471, 0), UDim2.new(0.68, 0,0.681, 0)}
}

for i, v in pairs(Sides) do
-- i is SideOne
-- v is Assigned table
for _, b in pairs(v) do
-- b is the UDim2 values
print(b)
end
end
3 Likes