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

Is this how you use the return function?

For example:

thing = false

function okay()
wait(2)
if thing == false then
print ("Hello World!")
thing = true
return okay()
elseif thing == true then
print("Goodbye!")
end
end

If it works correctly, it should print hello world, and then goodbye.

1 comment

0

after 2 seconds.

3 answers

✓ Accepted answer

return "returns" a value of a function. For example:

local function returnOne()
	return 1
end

The function above will return 1. Example:

print(returnOne()) --> 1

print(returnOne()+10)-->11

However functions are useful because you can give them arguments, and you can return different things based on the arguments.

local function evenNumberCheck(num)
	return num%2==0
end
%, or modulus, gives the remainder.

The above function will check if numbers are even, and return a bool based on that. Example:

print(evenNumberCheck(1)) --> false

print(evenNumberCheck(6)) --> true

if(evenNumberCheck(8*2))then
	print("8*2 makes an even number")
else
	print("8*2 doesn't make an even number")
end

For more info, I suggest reading this answer to the same question.

You use return to get the value of a function and to stop it

You would use return to get the value of a function.

local a = true
local b = true

function ReturnValues()
return a and b
end


function PrintValues()
print(tostring(ReturnValues())) --tostring converts things to strings
end

PrintValues()

2 comments

0

so basically, does it go back to the start of the script? (or as specified?)

0

it'll go back to where it was called. 

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