In loops like these, generally i and v are used. i is the index, or key, & v is the value.
Consider this table:
local tab = {
["Pies"] = "Delicious!",
["Cookies"] = "Scrumptious!",
["Salads"] = "..Eh.",
}
If we used an in pairs loop on this table, it would look something like this:
local tab = {
["Pies"] = "Delicious!",
["Cookies"] = "Scrumptious!",
["Salads"] = "..Eh.",
}
for i, v in pairs(tab) do
print(i .." are " ..v)
end
This would print:
"Pies are Delicious!", "Cookies are Scrumptious!", and "Salads are ..Eh.".
Now imagine 'tab' is 'poweredAxles'; "Delicious", "Scrumptious", and "Eh" would be the children of it.
When you get the children of an instance, it returns a table of those children. So, looping through them is the same as looping through a table. Each iteration of the loop is a different child within whatever you're getting the parent of.
So, inside of the SetThrottle function, it attempts to loop through 'poweredAxles' and set the BodyVelocity of each child (represented by v).
The script seems to have some issues, though:
local poweredAxles = script.Parent.Parent.Parent.Parent.R46ACar.MovingParts
function SetThrottle( newThrottle )
for _,v in pairs(poweredAxles:GetChildren()) do
v.BodyVelocity.Velocity = v.CFrame.lookVector * newThrottle * 280
end
end
Hope this helped!
1 comment
V is equal to the child inside newThrottle that is selected from the loop