Convert string to enum material

Hi, I want to convert a string to an enum for my code because I have to make customisable statues, and I want them to have customisable material. So, here is my code:

local Players = game:GetService("Players")
local Player = game:GetService("Players").LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Statue = workspace.Statue.Char

local Players = game:GetService("Players")
local Player = game:GetService("Players").LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Statue = workspace.Statue.Char -- Assuming "Statue" is a Model in the workspace

-- Player Item Functions

function Accessory(v, Material, Color) -- Accessory Function
	local Handle = v:FindFirstChildWhichIsA("MeshPart")
	
	Handle.TextureID = ""
	Handle.Material = Material
	Handle.Color = Color
end

function MeshPart(v, Material, Color) -- Part Function
	v.Material = Material
	v.Color = Color
end

function BaseAppearance(Morph, MorphHumanoid, Scale, Material, Color)
	MorphHumanoid:WaitForChild("BodyHeightScale").Value *= Scale
	MorphHumanoid:WaitForChild("BodyDepthScale").Value *= Scale
	MorphHumanoid:WaitForChild("BodyWidthScale").Value *= Scale
	MorphHumanoid:WaitForChild("HeadScale").Value *= Scale
	
	for i, v in pairs(Morph:GetChildren()) do
		if v:IsA("Pants") then
			v.PantsTemplate = ""
		elseif v:IsA("Shirt") then
			v.ShirtTemplate = ""
		elseif v:IsA("ShirtGraphic") then
			v:Destroy()
		elseif v:IsA("Accessory") then
			Accessory(v, Material, Color)
		elseif v:IsA("MeshPart") then
			MeshPart(v, Material, Color)
		end
	end
	
	MorphHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end
function StatueAppearance()
	-- Variables
	
	Character.Archivable = true
	local CharacterMorph = Character:Clone()
	local MorphHumanoid = CharacterMorph:WaitForChild("Humanoid")
	-- Statue Body Appearance Variables
	
	local Leaderstats_Material = Player:WaitForChild("Material").Value
	local Scale = 15
	local Material = (Enum.Material.)
	local Color = Color3.new(0, 0.662272, 0.0386664)
	-- Statue Position
	
	CharacterMorph:SetPrimaryPartCFrame(Statue.PrimaryPart.CFrame) -- Set the character's position to match the Statue's position
	-- Revert the statue to normal and set all the changes
	
	Statue:ClearAllChildren()
	CharacterMorph.Parent = Statue
	BaseAppearance(CharacterMorph, MorphHumanoid, Scale, Material, Color)
	Character.Archivable = false
end

StatueAppearance()

The place I want to edit is line 62-64. I need to do Enum.Material.(Whatever the player material is).

Please help, and thanks in advance.

To convert a string to Enum, use square brackets

Example

Material = Enum.Material["Neon"] -- Or any other string so long as it's a material

So would I do:

Material = Enum.Material["Leaderstat_Material"]

In your case, without the quotation marks because you’re trying to the value of a variable

Material = Enum.Material[Leaderstat_Material]
1 Like

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