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

What is `return false` and `return true` for?

I sometimes see in scripts return false and return true, what are they used for, and how do they work? I see them in functions mainly.

1 answer

Returns are a way of getting information out of a function. For example:

function add(a,b)
    return a+b
end

This will add 2 numbers, then return the result. Now, if we do this:

add(1,3)

Lua will see it as "4".

A more practical example:

function add(a,b)
    return a+b
end

print(add(3,7)) --output: 10

You can use this with booleans as well.

local thing = false

function check()
    if thing == false then
        return false
    else
        return true
    end
end

print(check())
--output: false

thing = true
print(check())
--output: true

1 comment

0

Thanks man! I wasn't too sure of what return was used for, this helps allot! +1

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