I've seen some scripts using a i,v in pairs do loop and looking at the wiki wasn't really clear, could someone give an example as to what exactly it does? Like compared to a i=1,#tableName do loop, what is the difference between them?
"for i, v in pairs" is a for loop. You can use it to search through different things to find something. It also has a perimeter on it. So, say you're searching through workspace for something. Your perimeter would be "(workspace:GetChildren())". I know, this may seem hard to understand, but here it is in script form.
In this script, I made a hat remover. "While wait() do" is the loop. Then, you use the for loop to search through workspace. After that, it uses "IsA" to check if "v" is a hat. v is everything in workspace. What I mean by that is you use "v in pairs(workspace:GetChildren()) do", which makes v the children of workspace. Then finally, the script destroys v if it's a hat.
while wait() do for i, v i pairs(workspace:GetChildren()) do if v:IsA("Hat") then v:Destroy() end end end
"for i, v in pairs" isn't only used for this, it can be helpful along the way. You can make a disco floor, disappearing plates, and many other things.
If this helped, make sure to accept this as your answer and upvote me!