:GetChildren Getting Ordered Instead Of Random?

Basically, my :GetChildren function isn’t getting the values in order, it is displaying a random one first and THEN going in order. Here is the code if you need it:

for i, Line in pairs(Lines:GetChildren()) do
					local Text = Line.Value
					
					for i = 1, #Text do
						LineLabel.Text = string.sub(Text, 1, i)
						Sounds.Talk:Play()
						if Skip == true then
							LineLabel.Text = Text
							Skip = false
							break
						end
						if Exit == true then
							break
						end
						wait(0.07)
					end
					if Exit == true then
						Exit = false
						break
					end
					repeat wait() until Skip == true or Exit == true
					Skip = false
				end

iirc it isnt meant to get it in order, you could use table.sort. I would suggest looking at this post: Sorting a GetChildren table

Okay, I sorted them into a table using this:

local linestable = Lines:GetChildren()
					table.sort(linestable, function(a,b,c)
						local name1 = tonumber(a.Name:match("%d+"))
						local name2 = tonumber(b.Name:match("%d+"))
						return name1 < name2
					end)

But how do I access the values from the table rather than the GetChildren line?

for i, Line in pairs(linestable) do

Okay, I’m not sure I’m doing this right so could you check the table and see if I am?

for i, Line in pairs(Lines:GetChildren()) do
					local linestable = Lines:GetChildren()
					table.sort(linestable, function(a,b,c)
						local name1 = tonumber(a.Name:match("%d+"))
						local name2 = tonumber(b.Name:match("%d+"))
						return name1 < name2
					end)
					local Text = Line.Value
					
					for i, Line in pairs(linestable) do
						for i = 1, #Text do
								LineLabel.Text = string.sub(Text, 1, i)
								Sounds.Talk:Play()
								if Skip == true then
									LineLabel.Text = Text
									Skip = false
									break
								end
								if Exit == true then
									break
								end
								wait(0.07)
							end
							if Exit == true then
								Exit = false
								break
							end
							repeat wait() until Skip == true or Exit == true
							Skip = false
						end

						Exit = false
						Skip = false

						PromptLabel:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear", 0.2)
						LineLabel.Visible = true

						wait(0.5)

						Chatting = false
						Detected = false
				end
			end
		end
	end
end)

Right now, it doesn’t display the first one first.


local linestable = Lines:GetChildren()
table.sort(linestable, function(a,b,c)
	local name1 = tonumber(a.Name:match("%d+"))
	local name2 = tonumber(b.Name:match("%d+"))
	return name1 < name2
end)

for i, Line in pairs(linestable) do
	local Text = Line.Value

	for i = 1, #Text do
		LineLabel.Text = string.sub(Text, 1, i)
		Sounds.Talk:Play()
		if Skip == true then
			LineLabel.Text = Text
			Skip = false
			break
		end
		if Exit == true then
			break
		end
		wait(0.07)
	end
	if Exit == true then
		Exit = false
		break
	end
	repeat wait() until Skip == true or Exit == true
	Skip = false
end

Exit = false
Skip = false

PromptLabel:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear", 0.2)
LineLabel.Visible = true

wait(0.5)

Chatting = false
Detected = false

That works, but kind of breaks it as now it is still trying to send the message even when Exit = true, any idea how to fix this?

Bump bumping bumpity bump bump bump

Use ipairs instead of pairs. --Minimum character limit

for i, Line in pairs(Lines:GetChildren())

to

for i, Line in ipairs(Lines:GetChildren())