How to print the floor material without "Enum.Material..."

So i try to detect wich material the player is walking on, then print it but, it print “Enum.Material.Plastic” and i want it to only print “Plastic”.

Here is my code:

--	// FileName: walkmaterial.lua
--	// Written by: Metafolder
--	// Description: change walk speed with material.

local WalkMaterialModule = {}

function WalkMaterialModule.Detect()
    local Source = script.Parent.Parent.Parent
    local GlobalVar = require(Source.Variable.variable)
    local SpeedChanger = require(Source.Event.PlayerFolder.PlayerModule.speedchanger)

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

        if Humanoid.MoveDirection.Magnitude > 0 and LastMaterial ~= Humanoid.FloorMaterial then
            LastMaterial = Humanoid.FloorMaterial
            print(LastMaterial) --Then it print "Enum.Material.Plastic"

return WalkMaterialModule

1 Like

Option 1(uses string and table operations, not ideal):

function enumToString(enum: EnumItem): string
	local parts = tostring(enum):split(".")
	return parts[#parts]

print(enumToString(Enum.Material.Plastic)) --Plastic

Option 2(does none of the above, probably quicker):

function enumToString(enum: EnumItem): string 
	return enum.Name 

print(enumToString(Enum.Material.Plastic)) --Plastic

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