How come, this table doesn't print out in order?

local hairButtons = {
	hair1 = hairScrollingFrame:WaitForChild('ViewportFrame1'),
	hair2 = hairScrollingFrame:WaitForChild('ViewportFrame2'),
	hair3 = hairScrollingFrame:WaitForChild('ViewportFrame3'),
	hair4 = hairScrollingFrame:WaitForChild('ViewportFrame4'),
	hair5 = hairScrollingFrame:WaitForChild('ViewportFrame5'),
	hair6 = hairScrollingFrame:WaitForChild('ViewportFrame6')
}

for key, button in pairs(hairButtons) do
	print("Key:", key, "Button:", button)
end

Output:

13:44:11.373 Key: hair5 Button: ViewportFrame5 - Client - LocalScript:32
13:44:11.374 Key: hair4 Button: ViewportFrame4 - Client - LocalScript:32
13:44:11.376 Key: hair2 Button: ViewportFrame2 - Client - LocalScript:32
13:44:11.376 Key: hair1 Button: ViewportFrame1 - Client - LocalScript:32
13:44:11.377 Key: hair3 Button: ViewportFrame3 - Client - LocalScript:32
13:44:11.378 Key: hair6 Button: ViewportFrame6 - Client - LocalScript:32

2 Likes

Dictionaries don’t print in order. Only arrays do.

1 Like

How can I sort this? /////////////////

1 Like

Just make it an array and use hairButtons[1] to index them.

1 Like

You can’t. Just use an array like @txcIove said.

Code:

local hairButtons = {
	hairScrollingFrame:WaitForChild('ViewportFrame1'),
	hairScrollingFrame:WaitForChild('ViewportFrame2'),
	hairScrollingFrame:WaitForChild('ViewportFrame3'),
	hairScrollingFrame:WaitForChild('ViewportFrame4'),
	hairScrollingFrame:WaitForChild('ViewportFrame5'),
	hairScrollingFrame:WaitForChild('ViewportFrame6')
}

for i, button in ipairs(hairButtons) do
	print("Key:", "hair".. i, "Button:", button)
end

I need to identify each index later though. Rip I’ll just add numbers to their names and do a search.

or why not just setting the index like [“hair1”] and so on then using:

on the index

That only works on arrays. You won’t be able to sort indices.

1 Like