agit_games
(AgitGames)
1
for i = 1, #Frame do
local child = FrameChild[i]
if FrameChild:IsA("TextButton") then
FrameChild.Active = false
end
task.wait(1)
end
for i, v in pairs(Frame:GetChildren()) do
if v:IsA("TextButton") then
v.Active = false
end
task.wait(1)
end
What are the differences between them?
px_qz
(px_qz)
2
i,v in pairs() loops through a table, i = 1 loops the amount of times you set it to
The first loop is a numerical loop. i is simply the current iteration the loop is on.
The second loop is a generic for loop. It returns the current index and value the iteration is on for the provided table.
The difference is one returns another value, while the other doesn’t (it simply iterates through numbers).
2 Likes
agit_games
(AgitGames)
4
Thanks to u both and for what can i use them both i tried them both it works the same for what are each for
MeowzzMr
(MrMeowzz)
5
well when looping through a table you get both the index and the value instead of just the index
with a for loop you can choose a starting index and choose a different increment value
in my opinion its easier to just loop through the table
zcole96
(Cole)
7
Lets say you have a table with 3 values in it.
Table = {“A”,“B”,“C”}
If you wanted to use pairs, you could do:
for i,v in pairs(Table) do
print(i,v)
end
In this case, i is equal to the position you’re at in the array, and v is equal to the value at that position.
You could expect your output to look like this:
1 A
2 B
3 C
This is in essence the same as doing this:
for i = 1,#Table do
v = Table[i]
print(v)
end