How to change player's body material

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == "/material" then
				for _, child in plr.Character:GetDescendants() do
					if child:IsA("BasePart") then
						child.Material = Enum.Material.neon
		end
	end)

how do i make if player type /material it change all their body part material to neon
lmk if y know where i did go wrong

1 Like

You’re missing a few end lines for your for and if blocks, and the PlayerAdded connection. Do you have your output enabled in Studio? It should have told you that.

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == "/material" then
			for _, child in plr.Character:GetDescendants() do
				if child:IsA("BasePart") then
					child.Material = Enum.Material.Neon -- Neon should be capitalized.
				end
			end
		end
	end)
end)
3 Likes

thx for d help btw, d y know by any chance to change it’s material by typing material’s name like /material grass ← or neon etc

1 Like

Try this script (which used @Hypgnosis as a starter):

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		local msg = msg:split(" ")
		
		if msg[1] == "/material" then
			local material = string.gsub(msg[2], "^%l", function(newMsg) return string.upper(newMsg) end)
			
			if Enum.Material[material] then
				for _, child in plr.Character:GetDescendants() do
					if child:IsA("BasePart") then
						print(Enum.Material[material])
						
						child.Material = Enum.Material[material]
					end
				end
			end
		end
	end)
end)

NOTE: Two things to mention:

  1. If the material you say after /material isn’t a valid material according to Enum.Material, it will throw an error. But, it works if you say a valid material no matter what, so it shouldn’t be an issue.
  2. Not a problem with the script, but just to put it out there, there are quite a couple materials don’t really have their effect work on the player’s character.
3 Likes