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

difference between end and return?

I cannot rap my head around that.

1 answer

The end keyword ends a block, such as a function or an if statement. The return keyword, however, stops execution of a function and returns the value you provide after the keyword. If you don't provide any value, it will return nil.

function test(s)
	if s == 2 then
		return "hello"
	elseif s == 3 then
		return
	elseif s == 4 then
		return 50
	end
	return "yolo"
end

print( test(2) )
--> hello

print( test(3) )
--> nil

print( test(4) )
--> 50

print( test() )
--> "yolo"

print( test('yo dawg') )
--> "yolo"

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