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