This question was originally asked here: Help with material changing
by @Q_ubit.
As you can see in the video below, my head material changes to brick, diamond plate, corroded metal and neon. Normally, if you tried to change any parts material color on the humanoid it would not work. But there is a pretty simple work around this issue.
The code below is a demonstration on how to change the players head material. Put it in a server script inside of ServerScriptService. What it does is clone the players head, then makes the original head transparent. From there, it welds the fake head onto the original head so it follows the same position.
--script in ServerScriptService
--Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--Method to change the head material
local function changeMaterial(character)
--Clones the players head and sets the original head to be transparent
local fakeHead = character.Head:Clone()
fakeHead.Parent = character.Head
fakeHead.CFrame = character.Head.CFrame
fakeHead.Name = "fakeHead"
fakeHead.Material = "SmoothPlastic"
character.Head.Transparency = 1
--Deleting all the irrelevant items in the head like the attachments, motor6d, etc. And just keeping the face
for _, part in pairs(fakeHead:GetChildren())do
if(part.Name ~= "face")then
part:Destroy()
end
end
--IMPORTANT PART
--Creating a weld constraint to connect the new fake head onto the player
local WeldConstraint = Instance.new("WeldConstraint")
WeldConstraint.Parent = fakeHead
WeldConstraint.Part0 = fakeHead
WeldConstraint.Part1 = character.Head
end
--Three functions below make sure the players head is changed
--when they join the game and when they die
local function onCharacterSpawned(player)
player.CharacterAppearanceLoaded:Connect(changeMaterial)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(function ()
onCharacterSpawned(player)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
I was also looking how to change all the parts material. Like the video below v
The code below does essentially the same thing as the fake head, but for all your body parts. Only downside I found was that the clothing does not come with the player. Also made it a bit more organized by creating a folder inside the player and adding all the parts there.
--script in ServerScriptService
--Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--Method to change the head material
local function changeMaterial(character)
local fakeParts = Instance.new("Folder")
fakeParts.Parent = character
fakeParts.Name = "fakeParts"
--Clones the entire player and sets the original head to be transparent
for key, meshPart in pairs(character:GetChildren())do
if (meshPart:isA("MeshPart")) then
local fakePart = meshPart:Clone()
fakePart.Parent = fakeParts
fakePart.CFrame = meshPart.CFrame
fakePart.Name = "fake"..meshPart.Name
fakePart.Material = "Neon"
--IMPORTANT PART
--Creating a weld constraint to connect the new fake head onto the player
local WeldConstraint = Instance.new("WeldConstraint")
WeldConstraint.Parent = fakePart
WeldConstraint.Part0 = fakePart
WeldConstraint.Part1 = meshPart
--Actually important, if you delete the animations wont work
--Deleting all the irrelevant items in the head like the attachments, motor6d, etc. And just keeping the face
for _, part in pairs(fakePart:GetChildren())do
print(part)
if(part.Name ~= "face" and part ~= WeldConstraint)then
print(part)
part:Destroy()
end
end
meshPart.Transparency = 1
end
end
end
--Three functions below make sure the players head is changed
--when they join the game and when they die
local function onCharacterSpawned(player)
player.CharacterAppearanceLoaded:Connect(changeMaterial)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(function ()
onCharacterSpawned(player)
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Hope this helps someone searching how to change the players head material