Changing a shirt through a script

I’m currently trying to make a system that allows players to set a shirt ID onto a dummy.

When I try to set it through the script, it does not work, however when I set it in the explorer, it actually changes

-- Create a new Shirt instance and set the template
local newShirt = Instance.new("Shirt")
newShirt.ShirtTemplate = "http://www.roblox.com/asset/?id=" .. assetID
newShirt.Parent = rig  -- Parent it to the rig directly
print("Shirt created and parented to the rig.")

-- Force refresh by setting ShirtTemplate again (helps with rendering delay)
wait(0.5)  -- Slight delay to allow template to load
newShirt.ShirtTemplate = newShirt.ShirtTemplate
print("ShirtTemplate refreshed to ensure loading.")

I am posting this on somebody’s behalf, and I’m able to provide more context if necessary.

Did you use :Destroy() on the old shirt or parent it somewhere else?

Use InsertService.

local InsertService = game:GetService("InsertService")
local Rig = script.Parent

local function loadShirt(AssetId)
	local success, shirt = pcall(function()
		return InsertService:LoadAsset(AssetId)
	end)
	
	if success then
		local shirt : Clothing = shirt:GetChildren()[1]
		return shirt
	end
end


local asset = loadShirt(AssetId)
if asset then
	asset.Parent = Rig
end
1 Like