I have seen people use for i,v in pairs in many places like tables and also in creating a round system but didn't get the answer how it is done and why only we use for i,v in pairs for on creating round system and many things i know that you can use it for tables but i don't know what is the more use of it as i see many people use it for diff rent things.
for i,v in pairs() is basically a for loop that loops through every item in a table. Although for i,v works just fine, for key,(word to help understand) works just the same, but in a more understandable way.
Anyways, lets say you wanted to unanchor all the parts in a model. Unanchoring every part individually would take a long time. for loops do that for you. Example:
local model = --model goes here for key,obj in pairs(model:GetChildren()) do obj.Anchored = false end
You can use a for loop whenever, like when a part is touched.
local model = --model again local hitbox = model.Hitbox --You don't need a hitbox as you can call the function when any part is touched, it just helps local function collapse() for key,obj in pairs(model:GetChildren()) do obj.Anchored = false end end hitbox.Touched:Connect(collapse)
I hope this makes things a lot more clear for you.
Marked as Duplicate by JesseSong
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?