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

How can I set a text to a part's material name?

Asked by 5 years ago

I used the following code:

TextLabel.Text = tostring(part.Material)

However, this sets the text to: 'Enum.Wood.Material', instead of 'Wood'. Is there a way to get the material name without having to use a 'if part.Material == Enum.Material.Wood then ..'?

1 answer

Log in to vote
1
Answered by 5 years ago

Use substrings.

print(string.sub(
    tostring(Enum.Material.Glass),15,20)
)
-- "Glass"

'Enum.Material.' takes up 15 characters, so it just comes down to finding everything after those.

0
Ah, forgot about that thanks awesomeipod 607 — 5y
Ad

Answer this question