Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Where does Return "return" to in these statements?

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.Parentthen will still insert Hit.Parentinto Selected? Or does it "return" to the last end? Thanks!

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.