Clothes are not displayed on the player bundle

I created this script for a game where you can try on various rich outfits by clicking on a button. Everything works except for one thing, and that is that the clothing (which is in the script) is not applied to the bundle that the player is wearing. I have already looked at the error box but no error messages were displayed there.
Does anyone know what I did wrong?


local replicatedStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")
local players = game:GetService("Players")
local assetService = game:GetService("AssetService")
local changeEvent = replicatedStorage:WaitForChild("ChangeClothesAndAccessories")
local newShirtId = 17455580758
local newPantsId = 172750508
local newHairId = 9726877283  -- Replace with the actual hair asset ID
local newAccessories = {
	96079043,
	4506963722,
	6682339691,
	6414371617,
	13398965847,
	17758492892,
	10875654340,
	15133946399,
	6134532324,
	12872970789,
	-- Add more accessory IDs as needed
}
local newBundleId = 239

-- Function to remove old clothes and accessories
local function removeOldClothesAndAccessories(character)
	-- Remove old clothes
	for _, child in pairs(character:GetChildren()) do
		if child:IsA("Shirt") or child:IsA("Pants") then
			child:Destroy()
		end
	end

	-- Remove old accessories
	for _, child in pairs(character:GetChildren()) do
		if child:IsA("Accessory") then
			child:Destroy()
		end
	end

	-- Remove old tools
	for _, tool in pairs(character:GetChildren()) do
		if tool:IsA("Tool") then
			tool:Destroy()
		end
	end

	-- Remove old hair
	for _, child in pairs(character:GetChildren()) do
		if child:IsA("Accessory") and child.AccessoryType == Enum.AccessoryType.Hair then
			child:Destroy()
		end
	end
end

-- Function to add new clothes and accessories
local function addNewClothesAndAccessories(character, player)
	-- Add new shirt
	local newShirt = Instance.new("Shirt", character)
	newShirt.ShirtTemplate = "rbxassetid://" .. newShirtId

	-- Add new pants
	local newPants = Instance.new("Pants", character)
	newPants.PantsTemplate = "rbxassetid://" .. newPantsId

	-- Add new hair
	local success, hairModel = pcall(function()
		return game:GetService("InsertService"):LoadAsset(newHairId)
	end)
	if success then
		local hair = hairModel:FindFirstChildOfClass("Accessory")
		if hair then
			hair.Parent = character
		end
		hairModel:Destroy()
	else
		warn("Failed to load hair with ID: " .. tostring(newHairId))
	end

	-- Add new accessories
	for _, accessoryId in ipairs(newAccessories) do
		local success, accessoryModel = pcall(function()
			return game:GetService("InsertService"):LoadAsset(accessoryId)
		end)
		if success then
			local accessory = accessoryModel:FindFirstChildOfClass("Accessory")
			if accessory then
				accessory.Parent = character
			end
			accessoryModel:Destroy()
		else
			warn("Failed to load accessory with ID: " .. tostring(accessoryId))
		end
	end

	-- Add new tools from ServerStorage
	local vipToolsFolder = serverStorage:FindFirstChild("VIPTools")
	if vipToolsFolder then
		for _, tool in pairs(vipToolsFolder:GetChildren()) do
			if tool:IsA("Tool") then
				local clonedTool = tool:Clone()
				clonedTool.Parent = player.Backpack
			end
		end
	else
		warn("VIPTools folder not found in ServerStorage")
	end
end

-- Function to apply new bundle
local function applyNewBundle(humanoid, bundleId)
	if bundleId then
		humanoid.RequiresNeck = false

		local function tryGet(context, object, funcName, ...)
			local success, result = pcall(object[funcName], object, ...)

			if success then
				return result
			else
				warn("Invalid", context .. ':', ..., "(Error:", result .. ')')
			end
		end

		local bundle
		local info = tryGet("BundleId", assetService, "GetBundleDetailsAsync", bundleId)

		if info then
			local id = 0

			for _, item in pairs(info.Items) do
				if item.Type == "UserOutfit" then
					id = item.Id
					break
				end
			end

			if id > 0 then
				bundle = tryGet("Bundle", players, "GetHumanoidDescriptionFromOutfitId", id)
			end
		end

		if bundle then
			humanoid:ApplyDescription(bundle)
		end
	end
end

-- Function to handle the RemoteEvent
local function onChangeClothesAndAccessories(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		applyNewBundle(humanoid, newBundleId)
		removeOldClothesAndAccessories(character)
		addNewClothesAndAccessories(character, player)

		-- Make parts invisible
		local partsToHide = {"RightFoot", "RightLowerLeg", "RightUpperLeg", "Head"}
		for _, partName in ipairs(partsToHide) do
			local part = character:FindFirstChild(partName)
			if part then
				part.Transparency = 1
			end
		end

		-- Remove face
		local face = character.Head:FindFirstChildOfClass("Decal")
		if face then
			face:Destroy()
		end
	end
end

changeEvent.OnServerEvent:Connect(onChangeClothesAndAccessories)

I have now only specified the script for the ServerScriptService so the other is not relevant (because everything works except that the shirt and pants are applied to the bundle)

2 Likes

When creating a piece of clothing, you upload two assets. 1 is the catalog item you purchase to use the shirt, and 2, the raw image file for it.

The ShirtTemplate property of class Shirt requires that image file, not the catalog item.

You can get the raw image file by:

Adding a temporary Shirt instance in the explorer, then pasting the shirt’s id in the ShirtTemplate. Roblox Studio will automatically convert that shirt’s id into the associated image file’s id (copy it, then set newShirtId as it), but won’t automatically convert when changing it with a script.

If you want to convert it with a script, you can use LoadAsset() to load in the model, which will contain a Shirt instance with the id. You might be able to use AssetService but I haven’t looked lol…

3 Likes

If i am honest i cant Script that well, cant i Just Insert a Script that Put the Image from the Shirt on the bundle? And when IT IS possible, how would a Script Like that Looks Like?

1 Like

What? You can’t just paste a decal of the Shirt’s Texture as a direct replacement for the Shirt?


When you use the :LoadAsset() function documentation, you can view the code sample, where the game attempts to insert a Model into the game. If you experiment with this function in-game, you’ll notice that the asset is parented in another Model. For example:

local InsertService  = game:GetService("InsertService")
local modelwithShirt = InsertService:LoadAsset("17455580758")
modelwithShirt.Parent = workspace -- You can change where you want to save this
local shirt = modelwithShirt.Shirt -- The actual Shirt object is parented by a Model

Using this knowledge, you can simply insert the Shirt object by using InsertService:LoadAsset(shirtIdhere) and parent it to anywhere you want, like a specific folder in Workspace.

You can then use a for loop to loop through the Player’s Character to search for a Shirt object, and code it such that it either:

  • Replace the current Shirt object should the Player’s character have a shirt on already, or
  • Add the Shirt object into the Player’s character if the character has no Shirt on.

This process can also be repeated for the Pants object as well.

You can try to refer to the official Documentation or search around the DevForum if you’re not sure how to implement certain concepts, that’s how you learn and improve in Scripting :)