Hello, so I'm tired of adding a bunch of if/elseif statements to my scripts where I have to check if the thing that got selected in a table matches to what I inputted, and I just think theres a better, and neater way to do this stuff.
Here's an example:
local foods = {"Apple", "Banana", "Grapes", "Carrot"}
function getColour(food)
if food == foods[1] then --Beyond here is a bit repetitive, how can I change this?
print("Red")
elseif food == foods[2] then
print("Yellow")
elseif food == foods[3] then
print("Purple")
elseif food == foods[4] then
print("Orange")
end
end
getColour("Banana")

2 comments
I have no idea why this was downvoted. Whoever did so is clearly ignorant to efficient practices. I apologize, I'll accept this for you!
Nice job, this script is way better than anything that could make.