What I want to do is that when I write “/material” and then write a material in the chat, it changes the material to my avatar, but I don’t know how to detect the materials.
local cmds = {
playerMaterial = "/material",
}
game.Players.PlayerAdded:Connect(function(plr)
-- Commands
plr.Chatted:Connect(function(msg)
if msg:sub(1,cmds.playerMaterial:len()):lower() == cmds.playerMaterial:lower() then -- Not relevant
local mat = msg:sub(cmds.playerMaterial:len()+1)--:lower() -- Detects the second word.
print(mat) -- prints the second word the player chatted (Material)
if Enum.Material:FindFirstChild(mat) then -- THIS IS MY DOUBT, AND I NEED HELP FOR THIS
print("material detected")
for _,v in pairs(plr.Character:GetDescendants()) do
if v:IsA("MeshPart") or v:IsA("BasePart") then v.Material = tostring(mat) end
end
end
end
end
end
Really need help to detect if the second player is a material.