So I’m working on a GUI that when clicked, another GUI will pop up and ask you to insert the ID of what it is you want to add to your character.
It works with everything except faces, I’m not sure what I’ve done wrong but I’ve been trying to fix it for hours.
Here is the script:
if not workspace:FindFirstChild("AvatarEvent") then
local event = Instance.new("RemoteEvent")
event.Name = "AvatarEvent"
event.Parent = workspace
end
local event = workspace.AvatarEvent
local insertS = game:GetService("InsertService")
event.OnServerEvent:Connect(function(player, id)
local number = tonumber(id)
if not number then return end
local asset
local char = player.Character
local success = pcall(function()
asset = insertS:LoadAsset(number)
end)
if not success then return end
local child = asset:GetChildren()
for _,v in pairs(child) do
if v:IsA("Accessory") then
char.Humanoid:AddAccessory(v)
elseif v:IsA("Shirt") then
local templ = v.ShirtTemplate
char.Shirt.ShirtTemplate = templ
elseif v:IsA("Pants") then
local templ = v.PantsTemplate
char.Pants.PantsTemplate = templ
elseif v:IsA("Decal") then
local templ = v.FaceTemplate
char.Face.FaceTemplate = templ
end
end
asset:Destroy()
end)
I’ve tried shirts, accessories, pants, hair… It all works except faces.
If anyone could just correct the script and tell me what I did wrong. It would honestly be such a relief.
I had the same porblem but with decals
Your problem is that the face id isnt the same has the image id , when you create a decal or a face first it creates a image and then creates the decal/face with a diferent id the sulution is looping the id down and trying to find one that is asset type 1 that is the image type and checking if the creator is the same.
Here is the function:
function getImageID(ID)
local result;
local getItemInfo = game:GetService('MarketplaceService');
local creator = getItemInfo:GetProductInfo(ID).Creator.Id;
local assetT = getItemInfo:GetProductInfo(ID).AssetTypeId;
if assetT == 18 then
repeat
ID = ID -1
until getItemInfo:GetProductInfo(ID).Creator.Id == creator and getItemInfo:GetProductInfo(ID).AssetTypeId == 1
result = ID
elseif getItemInfo:GetProductInfo(ID).AssetTypeId == 1 then
result = ID
else
result = 'Not a face!'
end
return result
end
it may take a while getting the image id becouse some faces have the image id too far apart but never takes too long.
Your script must get like this:
function getImageID(ID) --you can place this function anywhere on the script
local result;
local getItemInfo = game:GetService('MarketplaceService');
local creator = getItemInfo:GetProductInfo(ID).Creator.Id;
local assetT = getItemInfo:GetProductInfo(ID).AssetTypeId;
if assetT == 18 then
repeat
ID = ID -1
until getItemInfo:GetProductInfo(ID).Creator.Id == creator and getItemInfo:GetProductInfo(ID).AssetTypeId == 1
result = ID
elseif getItemInfo:GetProductInfo(ID).AssetTypeId == 1 then
result = ID
else
result = 'Not a face!'
end
return result
end
if not workspace:FindFirstChild("AvatarEvent") then
local event = Instance.new("RemoteEvent")
event.Name = "AvatarEvent"
event.Parent = workspace
end
local event = workspace.AvatarEvent
local insertS = game:GetService("InsertService")
event.OnServerEvent:Connect(function(player, id)
local number = tonumber(id)
if not number then return end
local asset
local char = player.Character
local success = pcall(function()
asset = insertS:LoadAsset(number)
end)
if not success then return end
local child = asset:GetChildren()
for _,v in pairs(child) do
if v:IsA("Accessory") then
char.Humanoid:AddAccessory(v)
elseif v:IsA("Shirt") then
local templ = v.ShirtTemplate
char.Shirt.ShirtTemplate = templ
elseif v:IsA("Pants") then
local templ = v.PantsTemplate
char.Pants.PantsTemplate = templ
elseif v:IsA("Decal") then
local templ = v.FaceTemplate
char.Face.FaceTemplate = getImageID(templ)
end
end
asset:Destroy()
end)
Sorry for the late reply i dont know if you still need help.
I didnt test that previous code and when i tested it wasnt working now i made it work.
if not workspace:FindFirstChild("AvatarEvent") then
local event = Instance.new("RemoteEvent")
event.Name = "AvatarEvent"
event.Parent = workspace
end
local event = workspace.AvatarEvent
local insertS = game:GetService("InsertService")
event.OnServerEvent:Connect(function(player, id)
local number = tonumber(id)
if not number then return end
local asset
local char = player.Character
local success = pcall(function()
asset = insertS:LoadAsset(number)
end)
if not success then return end
local child = asset:GetChildren()
for _,v in pairs(child) do
if v:IsA("Accessory") then
char.Humanoid:AddAccessory(v)
elseif v:IsA("Shirt") then
local templ = v.ShirtTemplate
char.Shirt.ShirtTemplate = templ
elseif v:IsA("Pants") then
local templ = v.PantsTemplate
char.Pants.PantsTemplate = templ
elseif v:IsA("Decal") then
char.Head.face.Texture = v.Texture -- this changes the face texture to the asset one
end
end
asset:Destroy()
end)