Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can you use return for conditional statements?

Asked by 4 years ago

Can you do this?

local function Search(Location, Value)
if Location[Value] then
local status = “found”
return(status)
end
end

local SearchStatus = Search(workspace, Part)
print(SearchStatus)
0
yes R_LabradorRetriever 198 — 4y
0
Yeah, but you don't have to put status in parentheses/brackets. You can just do "return status". AntiWorldliness 868 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Yes, you can do this. Very useful for classifying objects, too:

function isItLimeGreen(thing)
    if thing.BrickColor = BrickColor.new("Lime green") then
        return "True"
    else
        return "False"
    end
end

local object = game.Workspace:FindFirstChild("Test")
print( isItLimeGreen(object) )
Ad

Answer this question