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 5 years ago

Can you do this?

1local function Search(Location, Value)
2if Location[Value] then
3local status = “found”
4return(status)
5end
6end
7 
8local SearchStatus = Search(workspace, Part)
9print(SearchStatus)
0
yes R_LabradorRetriever 198 — 5y
0
Yeah, but you don't have to put status in parentheses/brackets. You can just do "return status". AntiWorldliness 868 — 5y

1 answer

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

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

01function isItLimeGreen(thing)
02    if thing.BrickColor = BrickColor.new("Lime green") then
03        return "True"
04    else
05        return "False"
06    end
07end
08 
09local object = game.Workspace:FindFirstChild("Test")
10print( isItLimeGreen(object) )
Ad

Answer this question