How to give a player a specific shirt?

Hello I currently am trying to give the player a specific shirt. Bassically the player enters a AssetID from the catalog and it gives that shirt.

here is my script

local function giveShirt(plr, id)
	local char = plr.Character
	
	if char:FindFirstChildOfClass("Shirt") then
		warn("gave shirt")
		char:FindFirstChildOfClass("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=" .. id
	end
end

the issue is that the AssetId from the catalog is not the same assetID used on shirtTemplates and therefor it will not work. I dont know how to convert the assetid from catalog to shirttemplate id.

So how do I convert the assetid from catalog to shirttemplate id?

3 Likes

local HttpService = game:GetService(“HttpService”)
local assetId = 123456789 – Replace with your AssetId

local function convertAssetIdToShirtTemplateId(assetId)
local url = string.format(“https://api.roblox.com/asset-thumbnail/image?assetId=%d&width=1&height=1”, assetId)
local response = HttpService:GetAsync(url, false)
local decodedResponse = HttpService:JSONDecode(response)
return decodedResponse.ShirtTemplateId
end

local shirtTemplateId = convertAssetIdToShirtTemplateId(assetId)
print(“ShirtTemplateId:”, shirtTemplateId)

This will hopefully print you the shirttemplate id.

3 Likes

Go to Game Settings and then avatar and scroll down until you see set avatar stuff

I just used insert service.

local Asset = 0 – put shirt id from catalog here
local plr = – somehow get a player instance

local newShirt = game:GetService(“InsertService”):LoadAsset(Asset)
newShirt:FindFirstChildOfClass(“Shirt”).Parent = plr.Character

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.