I've made a script that allows players to enter a catalog ID and either purchase or wear the item. Currently, players can purchase items but not wear them. The following is the code I've been attempting to use to place items onto players. For simplicities sake, the only code for putting items on is for pants, but even that is off.
local wear = script.Parent.Parent.WearButton local player = game.Players.LocalPlayer wear.MouseButton1Click:connect(function() local Id = script.Parent.Text local assetID = ("rbxassetid://"..Id) --asset link local avatarchange = player:GetChildren()-- Getting the children of player print ("Got to this part at least! and the id link is "..assetID) -- The furthest the code is run for i,v in pairs (avatarchange) do if (v.ClassName == "Pants") then print("Got to finding Pants") v.PantsTemplate = assetID print("Pants have been succesfully worn") end end end)
There are no errors that pop up, but it simply does not run. The three things I'm sure about is: 1. I most likely used the for function wrong 2. I most likely need multiple if statements for whether the ID is accessory, shirt or pants. 3. The accessories (from what I've seen), need weldfunctions. I've looked and am not quite sure how to implement this into the code.
Please, if you end up showing a proper script for this, explain it because this is in the realm that I have no expertise in.
Your avatarchange variable gets the contents of the player, not the player's character.
local wear = script.Parent.Parent.WearButton local player = game.Players.LocalPlayer wear.MouseButton1Click:connect(function() local Id = script.Parent.Text local assetID = ("rbxassetid://"..Id) --asset link local characterContents = player.Character:GetChildren() print ("Got to this part at least! and the id link is "..assetID) -- The furthest the code is run for i,v in pairs (characterContents) do if (v.ClassName == "Pants") then print("Got to finding Pants") v.PantsTemplate = assetID print("Pants have been succesfully worn") end end end)
You can add accessories on the catalog (has to be owned by either you or ROBLOX) by using InsertService.
ex
local InsertService = game:GetService("InsertService") local AssetID = 9999 function getAsset() local containerModel = InsertService:LoadAsset(AssetID) --when you load a asset, it's automatically stored into a model, so use a loop to get the asset local asset for i, v in pair(containerModel:GetChildren() do asset = v end print("got asset: " .. asset.Name) end
: