if Hit.Parent.Team.Value == TeamColor then if Hit.Parent.Class.Value == "Unit" then for i,v in pairs(Selected) do if v == Hit.Parent then return end end table.insert(Selected,Hit.Parent) end
Could somebody explain where return "returns" to in these statements? If v == Hit.Parent
then will still insert Hit.Parent
into Selected
? Or does it "return" to the last end? Thanks!
return
is used in a function to stop everything. Every loop will stop. Nothing after return
will be read.
You can also use return
to cause a function to stop, and then give you a value. But this isn't what's happening in your code - it's just stopping.
You can read more on the wiki.