Skins staying the same when changing

When I was making a shop, I made a Skin tab where If you equip a certain skin, it would be equipped instead of your own avatar. However, I had problems with it.

Avatar Skins not loading correctly
According to my ReplicatedStorage.Event script, right here:

function skinChanger(player, model)
	if model then
		--Clears Player current avatar
		for i,v in pairs(player.Character:GetChildren()) do
			if v:IsA("Hat") or v:IsA("Accessory") then
				v:Destroy()
			end
		end
		player.Character.Shirt.ShirtTemplate = ""
		player.Character.Pants.PantsTemplate = ""
		for i,v in pairs(player.Character:GetChildren()) do
			if v:IsA("CharacterMesh") then
				v:Destroy()
			end
		end

		--Begin avatar to skin proccess...

		player.Character.Shirt.ShirtTemplate = model.Shirt.ShirtTemplate
		player.Character.Pants.PantsTemplate = model.Pants.PantsTemplate
		player.Character["Body Colors"].HeadColor3 = model["Body Colors"].HeadColor3
		--Clears Player current avatar
		for i,v in pairs(player.Character:GetChildren()) do
			if v:IsA("Hat") or v:IsA("Accessory") then
				v:Destroy()
			end
		end
		player.Character.Shirt.ShirtTemplate = ""
		player.Character.Pants.PantsTemplate = ""
		for i,v in pairs(player.Character:GetChildren()) do
			if v:IsA("CharacterMesh") then
				v:Destroy()
			end
		end

		--Begin avatar to skin proccess...

		player.Character.Shirt.ShirtTemplate = model.Shirt.ShirtTemplate
		player.Character.Pants.PantsTemplate = model.Pants.PantsTemplate
		player.Character["Body Colors"].HeadColor3 = model["Body Colors"].HeadColor3
		player.Character["Body Colors"].LeftArmColor3 = model["Body Colors"].LeftArmColor3
		player.Character["Body Colors"].RightArmColor3 = model["Body Colors"].RightArmColor3
		player.Character["Body Colors"].LeftLegColor3 = model["Body Colors"].LeftLegColor3
		player.Character["Body Colors"].RightLegColor3 = model["Body Colors"].RightLegColor3
		player.Character["Body Colors"].TorsoColor3 = model["Body Colors"].TorsoColor3
		player.Character.Head.face.Texture = model.Head.face.Texture
		for i,v in pairs(model:GetChildren()) do
			if v:IsA("CharacterMesh") then
				v:Clone().Parent = player.Character
			end
		end
		for i,v in pairs(model:GetChildren()) do
			if v:IsA("Hat") or v:IsA("Accessory") then
				v:Clone().Parent = player.Character
				print(v.Name..": "..v.Parent.Name)
			end
		end
		player.Character["Body Colors"].LeftArmColor3 = model["Body Colors"].LeftArmColor3
		player.Character["Body Colors"].RightArmColor3 = model["Body Colors"].RightArmColor3
		player.Character["Body Colors"].LeftLegColor3 = model["Body Colors"].LeftLegColor3
		player.Character["Body Colors"].RightLegColor3 = model["Body Colors"].RightLegColor3
		player.Character["Body Colors"].TorsoColor3 = model["Body Colors"].TorsoColor3
		player.Character.Head.face.Texture = model.Head.face.Texture
		for i,v in pairs(model:GetChildren()) do
			if v:IsA("CharacterMesh") then
				v:Clone().Parent = player.Character
			end
		end
		for i,v in pairs(model:GetChildren()) do
			if v:IsA("Hat") or v:IsA("Accessory") then
				v:Clone().Parent = player.Character
				print(v.Name..": "..v.Parent.Name)
			end
		end
	end
end

game.ReplicatedStorage.SetSkin.OnServerEvent:Connect(function(plr, model)
	if model and model:IsA("Model") and model:FindFirstChild("Humanoid") then
		skinChanger(plr, model)
	end
end)

and the LocalScript when you equip a certain skin:

local ItemSelected = script.Parent.ItemSelected
local Skins = script.Parent.Skins

local Player = game.Players.LocalPlayer

local function setSkin(model)
	game.ReplicatedStorage.SetSkin:FireServer(model)
end


local function selectedItem(image,title,desc,skin,free,points)
	ItemSelected.ItemImage.Image = image
	ItemSelected.Title.Text = title
	ItemSelected.Description.Text = desc
	if free ~= false then
		ItemSelected.Buy.Text = "FREE"
	elseif points then
		ItemSelected.Buy.Text = points.." POINTS"
	end
	ItemSelected.Visible = true
	ItemSelected.Buy.MouseButton1Click:Connect(function()
		if free == true then
			setSkin(skin)
			ItemSelected.Buy.Text = "BOUGHT!"
		else
			if Player.leaderstats.Points.Value == points or Player.leaderstats.Points.Value > points then
				setSkin(skin)
				ItemSelected.Buy.Text = "BOUGHT!"
			else
				ItemSelected.Buy.Text = "NOT ENOUGH POINTS"
			end
		end
	end)
end

--All buttons
for i,v in pairs(Skins:GetChildren()) do
	v.MouseButton1Click:Connect(function()
		local latest = v
		local config = latest:WaitForChild("Configuration")
		
		selectedItem(latest.Image, config.Title.Value, config.Description.Value, config.Skin.Value, config.Free.Value, config.Free.Points.Value)
	end)
end

I tried fixing it other way, but it will still happen

1 Like

Here’s the demonstration on that same problem.
Noob Skin


Skin of my own avatar

1 Like

Why not use Humanoid:ApplyDescription? Put your dummies/templates in replicated storage or wherever, then apply that description to your avatar.

Well, you see… that’s the same thing,
I now know how to use Humanoid:ApplyDescription, but
the same thing happens, you can’t change to the other skin
while having the skin that you first equipped.

I have no idea where you got this from, You can apply a description, even when your avatar is already set. I made an example in studio:

I have a remote event called “ChangeAvatar” inside ReplicatedStorage and the rig/avatar I want to set it to, Then I have a server script in ServerScriptService with this code:

local Event = game.ReplicatedStorage.ChangeAvatar

Event.OnServerEvent:Connect(function(Player : Player, Skin)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	
	if not Character or not Humanoid then return end
	
	local Description = Skin.Humanoid:FindFirstChildOfClass("HumanoidDescription")
	if not Description then return end
	
	Humanoid:ApplyDescription(Description)
end)

And a local script inside a text button, with this code:

local Event = game.ReplicatedStorage.ChangeAvatar
local Button = script.Parent

local Player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	Event:FireServer(game.ReplicatedStorage.Rig)
end)

You can add more functionality, like implementing currency and viewports of whatever. But this is the basic model, and it works in studio.

What I am saying is,
ApplyDescription works…
But, If you try to equip the other skin whilst having the first one,
it won’t work.

I was playing around and made a version that works after equipping the first one, here you go, instead of applying a description to the humanoid, we make a new one and apply it to that one.

local Event = game.ReplicatedStorage.ChangeAvatar

local BodyColors = {
	"HeadColor",
	"LeftArmColor",
	"LeftLegColor",
	"RightArmColor",
	"RightLegColor",
	"TorsoColor"
}

local function GetHumanoidAndCharacter(player)
	local Character = player.Character or player.CharacterAdded:Wait()
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	
	return Character, Humanoid
end

local function removeExistingAccessories(character)
	for _, accessory in ipairs(character:GetChildren()) do
		if accessory:IsA("Accessory") then
			accessory:Destroy()
		end
	end
end

local function ApplyDescription(Humanoid : Humanoid, OriginalDescription : HumanoidDescription, Skin, Character)
	
	removeExistingAccessories(Character)
	
	for _, v in Skin:GetChildren() do
		if v:IsA("Accessory") then
			local clone = v:Clone()
			clone.Parent = Character
		end
	end
	
	local newDescription = Instance.new("HumanoidDescription")
	
	for _, v in ipairs(BodyColors) do
			newDescription[v] = OriginalDescription[v]
	end
	
	Humanoid:ApplyDescription(newDescription)
	
	newDescription:Destroy()
end

Event.OnServerEvent:Connect(function(Player : Player, Skin)
	local Character, Humanoid = GetHumanoidAndCharacter(Player)
	
	if not Character or not Humanoid then return end
	
	local Description = Skin.Humanoid and Skin.Humanoid:FindFirstChildOfClass("HumanoidDescription")
	if not Description then return end
	
	ApplyDescription(Humanoid, Description, Skin, Character)
end)