I'm not sure if for i,v in pairs would be useful in a basic rblx game. Since I don't understand it much(dont explain to me what it is), i will try to understand it more in the future when games would be important to me. And if so, can you explain why and an example of how you can use it?
Will for i,v in pairs be useful in basic rblx games?
1 answer
This is a special form of iteration designed to traverse through an array. The pairs() function will push the current index point, and element within the table at the respective point of iteration into two variables, i and v. These define Index and Value. These two variables can be named whatever you like, or ignored if not needed via using the special character _.
This is highly useful as it can allow us to perform multiple tasks on tones of Instances with barely any lines of code—or process a lot of information quickly—this is something you'll find yourself needing to do, or doing in several basic programs.
Let's take a look at a basic application, killing everyone in-game:
local Players = game:GetService("Players"):GetPlayers() --// Gives an array.
for _,Player in pairs(Players) do
if (Player.Character) then
local Humanoid = Player.Character:FindFirstChildOfClass("Humanoid")
if (Humanoid) then
Humanoid:TakeDamage(Humanoid.Health)
end
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

6 comments
Yes its really useful.
https://scriptinghelpers.org/questions/11516/can-someone-explain-this-for-iv-in-pairs-to-me
ill tell u
umm okay?
wait a sec ok?
Ok watch this vid :P
https://www.youtube.com/watch?v=KHWHBeDC3yE