How to do this without a million elseif's

Hello devs!

I’ve been making a plugin for the last few hours that lets you use tools to quickly create parts, save part settings, insert a player’s avatar and more.

When I got to the material part, I obviously have a whole bunch of buttons. I was wondering if anyone could tell me how I’d go about changing the material without using a million elseif statements. Obviously Enum.Material.VariableName wouldn’t work, and it’s 12 AM right now so my brain is working at 5% efficiency.

I’ve tried looking for problems similar on the devforum but came up short.


Here’s the list of materials I have:
image
image


I don’t think the code is necessary, but if you need some of the code I wrote I can supply!

Thank you in advance for any help at all!

Best regards,
Amora

Maybe make it get rid of it’s spaces and get the string that has no spaces and do this:

Enum.Material[nospacesthingy]

Gahhh! Thank you so much!
My brain is barely functioning right now and I can’t think at all. If I wasn’t so determined to finish this tonight I prob would’ve done that.

You’re a literal life saver! I’m so sleep deprived :sob:

iirc you can utilize Enum.Materials:GetEnumItems(), what this method does is just return an array of the enums, and since you are using them you can just use a for loop and iterate through the Enums and get all the info you need from them

1 Like

That too is efficient, but this only bases off one line of code.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.