Why are my pants not being applied?

I am trying to make an automated clothing script but for some reason it only applies the shirt and not the pants, any ideas what i have done wrong?


local shirtid = "" --Add the ID of the shirt here
local pantsid = "" --Add the ID of the pants here

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(chr)
		
		if plr.leaderstats2.Recruit.Value == true then
			shirtid = "4925410735" 
			pantsid = "502705252"
		end
		if plr.leaderstats2.Regular.Value == true then
			shirtid = "313656445"
			pantsid = "502705252"
		end
		if plr.leaderstats2.Desert.Value == true then
			shirtid = "4508458685"
			pantsid = "4508459277"
		end
		if plr.leaderstats2.Winter.Value == true then
			shirtid = "4489844052"
			pantsid = "4489844773"
		end
		if plr.leaderstats2.PT.Value == true then
			shirtid = "5553422901"
			pantsid = "502705252"
		end
		if plr.leaderstats2.Formal.Value == true then
			shirtid = "106747688"
			pantsid = "106745727"
		end
		
		
			local shirt = chr:FindFirstChild("Shirt")
			if shirt then
				shirt.ShirtTemplate = "rbxassetid://" ..shirtid
			else
				local nshirt = Instance.new("Shirt", chr)
				nshirt.Name = "Shirt"
				nshirt.ShirtTemplate = "rbxassetid://" ..shirtid
			end
			local pants = chr:FindFirstChild("Pants")
			if pants then
				pants.PantsTemplate = "rbxassetid://" ..pantsid
			else
				local npants = Instance.new("Pants", chr)
				npants.Name = "Pants"
				npants.PantsTemplate = "rbxassetid://" ..pantsid
			end
			--If you want to remove T-Shirts, then leave this code. If not, then erase that
			local tee = chr:FindFirstChild("ShirtGraphic")
			if tee then
				tee:Destroy()
			end

end)

end)
1 Like

Did you anchor them? That could be an issue! lol

2 Likes

What an… audience-engaging title

Anchor them?

8 Likes

I couldn’t help but click. This is too funny. I would definitely say anchor them and make sure who they are parented to. :laughing:

6 Likes

how do you anchor pants, they are a decal on the player

2 Likes

haha yes all anchored and i even added a belt, but still no pants, its embarrassing! :joy:

2 Likes

Weird, I wonder if you should post in #platform-feedback:studio-bugs
I would assume it is with that, however make sure you try many different pants. Some pants in Roblox don’t load. I guess Roblox really supports the title lol. @lucky_thirteen13

The pants have been working in game and still work when used outside of this script. I also have click giver parts that use the same pants and shirts and they work in studio and in Roblox itself.

Could you supply an image or a video of what’s happening, or potentially any errors that might be appearing in your console? I’m not so sure others understand the problem given the responses. Additionally, on another note, I would move the shirtsid and pantsid variables to the CharacterAdded function. Those variables shouldn’t be available to all scopes.

Also quick note: I changed the title to use better wording to prevent similar replies like “anchor them” when that appears not to be the issue.

1 Like

I had this issue in this topic:

I had to use insertservice and parent it in the character.

2 Likes

There is no errors given at all.
When a player picks an outfit in game via a click on a part it applies a shirt and pants to the player and assigns a bool value in leaderstats2 to true which is saved on the player exit. When the player reconnects this script is meant to re apply the choice of clothing items the player made during their last visit.
The script applies the shirt with no problem but for some reason does not apply the pants, a picture would just be me with no pants.
I have tried commenting out the shirt IDs and still the pants do not get applied.

The script you linked makes sense for a game which is team based and you wish to apply clothing dependent on which team a player is assigned. I am trying to allow each player to have a choice, and then that choice be saved and re applied when they rejoin. Can this be converted to do that?

Hm, last time I tried you can’t really use actual shirt IDs, shirt templates and shirts are different stuff basically. You can only get the shirt templates on studio if you do it manually, so check that. You can’t set these IDs as actual clothing; you need to get their “texture”, that’s basically how bad people steal clothing, you can simply paste the IDs inside a shirt object and it should get converted into it’s template.