What did I wrong?

I made a script to apply shirts and pants to the dummy. I attempted this and it seemed not to work or show any errors. What did I do wrong:

local MaleShirts = {
	"https://www.roblox.com/catalog/10476909222/",
	"https://www.roblox.com/catalog/14867469174/",
	"https://www.roblox.com/catalog/2043393684/",
	"https://www.roblox.com/catalog/10702131770/",
	"https://www.roblox.com/catalog/11560229918/"
}

local MalePants = {
	"https://www.roblox.com/catalog/9824426986/",
	"https://www.roblox.com/catalog/12215267334/",
	"https://www.roblox.com/catalog/11560229918/",
	"https://www.roblox.com/catalog/18219332947/",
	"https://www.roblox.com/catalog/2043393899/"
}

local MaleHair = {
	"https://www.roblox.com/catalog/12887129839/",
	"https://www.roblox.com/catalog/12911961302/",
	"https://www.roblox.com/catalog/16314636793/",
	"https://www.roblox.com/catalog/15569172395/",
	"https://www.roblox.com/catalog/18653473304/"
}

local FemaleShirts = {
	"https://www.roblox.com/catalog/15234276594/",
	"https://www.roblox.com/catalog/5926636822/",
	"https://www.roblox.com/catalog/6287440679/",
	"https://www.roblox.com/catalog/9252177953/",
	"https://www.roblox.com/catalog/8078107210/"
}

local FemalePants = {
	"https://www.roblox.com/catalog/12600337570/",
	"https://www.roblox.com/catalog/2779197890/",
	"https://www.roblox.com/catalog/2779197890/",
	"https://www.roblox.com/catalog/4677181042/",
	"https://www.roblox.com/catalog/479104585/",
	"https://www.roblox.com/catalog/6737011903/"
}

local FemaleHair = {
	"https://www.roblox.com/catalog/15643738220/",
	"https://www.roblox.com/catalog/88388283433140/",
	"https://www.roblox.com/catalog/17343731641/",
	"https://www.roblox.com/catalog/17120262338/",
	"https://www.roblox.com/catalog/14146138094/"
}

local function assignAppearance()
	local gender = math.random(1, 2) == 1 and "Male" or "Female"
	local shirtID = ""
	local pantsID = ""
	local hairID = ""

	if gender == "Male" then
		shirtID = MaleShirts[math.random(1, #MaleShirts)]
		pantsID = MalePants[math.random(1, #MalePants)]
		hairID = MaleHair[math.random(1, #MaleHair)]
	else
		shirtID = FemaleShirts[math.random(1, #FemaleShirts)]
		pantsID = FemalePants[math.random(1, #FemalePants)]
		hairID = FemaleHair[math.random(1, #FemaleHair)]
	end

	local humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
	local head = script.Parent:FindFirstChild("Head")
	local shirt = Instance.new("Shirt", script.Parent)
	local pants = Instance.new("Pants", script.Parent)
	
	shirt.ShirtTemplate = shirtID
	pants.PantsTemplate = pantsID
end

assignAppearance()
1 Like

Your script is correctly generating random clothing items, but Roblox URLs aren’t directly applicable to ShirtTemplate or PantsTemplate. Roblox clothing assets require the actual asset ID number, not the full catalog URL.

Consider using rbxassetid:// instead of https://www.roblox.com/catalog/. For example, replace https://www.roblox.com/catalog/10476909222/ with rbxassetid://10476909222.

local MaleShirts = {
	"rbxassetid://10476909222",
	"rbxassetid://14867469174",
	"rbxassetid://2043393684",
	"rbxassetid://10702131770",
	"rbxassetid://11560229918"
}

local MalePants = {
	"rbxassetid://9824426986",
	"rbxassetid://12215267334",
	"rbxassetid://11560229918",
	"rbxassetid://18219332947",
	"rbxassetid://2043393899"
}

local MaleHair = {
	"rbxassetid://12887129839",
	"rbxassetid://12911961302",
	"rbxassetid://16314636793",
	"rbxassetid://15569172395",
	"rbxassetid://18653473304"
}

local FemaleShirts = {
	"rbxassetid://15234276594",
	"rbxassetid://5926636822",
	"rbxassetid://6287440679",
	"rbxassetid://9252177953",
	"rbxassetid://8078107210"
}

local FemalePants = {
	"rbxassetid://12600337570",
	"rbxassetid://2779197890",
	"rbxassetid://2779197890",
	"rbxassetid://4677181042",
	"rbxassetid://479104585",
	"rbxassetid://6737011903"
}

local FemaleHair = {
	"rbxassetid://15643738220",
	"rbxassetid://88388283433140",
	"rbxassetid://17343731641",
	"rbxassetid://17120262338",
	"rbxassetid://14146138094"
}

local function assignAppearance()
	local gender = math.random(1, 2) == 1 and "Male" or "Female"
	local shirtID = ""
	local pantsID = ""
	local hairID = ""

	if gender == "Male" then
		shirtID = MaleShirts[math.random(1, #MaleShirts)]
		pantsID = MalePants[math.random(1, #MalePants)]
		hairID = MaleHair[math.random(1, #MaleHair)]
	else
		shirtID = FemaleShirts[math.random(1, #FemaleShirts)]
		pantsID = FemalePants[math.random(1, #FemalePants)]
		hairID = FemaleHair[math.random(1, #FemaleHair)]
	end

	local humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
	local head = script.Parent:FindFirstChild("Head")
	local shirt = Instance.new("Shirt", script.Parent)
	local pants = Instance.new("Pants", script.Parent)
	
	shirt.ShirtTemplate = shirtID
	pants.PantsTemplate = pantsID
end

assignAppearance()
1 Like

hmm, doesn’t seem to make a difference

1 Like

I found the issue, you can’t add shirts or pants directly during runtime, you must use ApplyDescription()

1 Like

Not sure what the cause could be then, but make sure of a few things:

  1. Parenting: Be certain that you are first parenting the Shirt and Pants instances templates. The lines shirt.Parent = script.Parent and pants.Parent = script.Parent should come after props.ShirtTemplate and props.PantsTemplate are set.

  2. Humanoid Check: Make sure that the parent of your script has a Humanoid and a Head. If no, your script will not work.

  3. Asset Validity: Make sure that the asset IDs are correct and are already uploaded.

  4. Check for errors: Check the output for errors while running the script.

1 Like

That’s great, didn’t see the message before sending a reply, heh. Happy developing!

1 Like

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