I know that this question may get closed down because it has been asked before but it never really answered the question. I'm not asking for what return does but i'm asking what's the purpose of putting an end after it? I've seen it used for debounces and such but i don't understand why people would use return end rather than just a normal debounces. So for what purpose does it serve?
COMMUNITY QUESTION
What's the purpose of return end?
1 answer
It is basically to stop the code from going. It is usualy used to break a while Wait() or while true loop. Here is a expample of me using it.
function MusicPlay()
if script.Parent:FindFirstChild("IntroSong") then return end
local Number = math.random(1,3)
print(Number)
if Number == 1 then
Music1()
elseif Number == 2 then
Music2()
elseif Number == 3 then
Music3()
end
end
In some cases like that one it is required.
1 comment
0
I don't think you can break a while loop with return. And a while wait() loop doesn't exist.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
To prevent the code from furthering; it's like returning a value and stopping the code there.
https://www.lua.org/pil/4.4.html