How can I wear a clothing from the Roblox catalog by clicking a button? (Classic shirt and Classic pants)
The following function should allow you to load Shirt and Pants instances from catalog ids:
local function loadClothing(id: string): Shirt | Pants?
local model = game.InsertService:LoadAsset(id)
local shirt = model:FindFirstChildOfClass("Shirt")
if shirt then return shirt end
return model:FindFirstChildOfClass("Pants")
end
The call to LoadAsset must be done on the server, this means that if you want to make a client UI with a textbox, you will need to create a remote event that sends the catalog id the user typed in the textbox to the server. The server after receiving the id, can respond by either loading the asset on the server side (for example an NPC all players can see), or it can return the ShirtTemplate/PantsTemplate string to the specific client firing the remote so they can create/load the asset themselves on the client side.
Also if you’re scared to run LoadAsset on the server side with user input passed to it, you can first call the following function, that tells you if the asset the user is trying to load is a classic shirt or pants:
local function isShirtOrPants(id: string): boolean
local info = game.MarketplaceService:GetProductInfoAsync(id)
--Shirt, Pants
return info.AssetTypeId == 11 or info.AssetTypeId == 12
end
Both of the functions I gave you can error if the id the user provides doesn’t exist, or if the server gets rate limited (if the user is spamming the remote). You should handle these situations with pcalls and error checking, along with rate limiting the event itself to prevent malicious behaviour.
To make your character wear the shirt/pants, all you have to do is parent them directly under their character in the workspace. If you know the player that clicks the button you can fetch their character from the player.Character variable, if the button is clicked in the local script you can fetch the player through game.Players.LocalPlayer.
They have plugins that can do this.. if that is what you’re asking about.
well put the id’s in a variable
when the button is clicked
the player’s shirt object id is changed for the id?
ig?