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:

   --!nonstrict
--	// 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

    Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
        if Humanoid.MoveDirection.Magnitude > 0 and LastMaterial ~= Humanoid.FloorMaterial then
            LastMaterial = Humanoid.FloorMaterial
            SpeedChanger.Set(LastMaterial)
            print(LastMaterial) --Then it print "Enum.Material.Plastic"
        end
    end)
end


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]
end

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

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

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

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

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