Can someone please explain to me how this code works?
for _, button in pairs(buttons:GetChildren()) do
button.Touched:Connect(function(otherpart)
local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
local touched = button:FindFirstChild("Touched") -- arguments of button
if humanoid and touched and touched.Value == false then
ab(button, touched)
end
end)
end
#Pairs
1 messages · Page 1 of 1 (latest)
for _, button in pairs(buttons:GetChildren()) gets every item inside of a folder/model
the first value (_) is the index, which counts how many objects have been counted
the second value (button) is the current object, and is what is referenced when the button variable is used
for i,v in pairs(folder:GetChildren()) do
print(v.Name)
end
would print the name of every object in a folder
the output would look like:
Part1
Part2
Part3
Part4
(if all of the names are ordered like that)
the first and second variables can be renamed like normal variables
Im still confused where the button variable came from
its just the name used for "v"
** You are now Level 7! **
it's made-up. you can put anything you want there. people usually pick names that make sense for what they're working with, but generally for _,v (_ for unused, v for value) and for k,v (k for key) are commonly used generic names.
k,v is my goat