Issue with "shirt" not being found

I have made a simple uniform giver, that changes the shirt and pants template. Now I found the issue whilst playing the game with friends, and I know what the issue is, I just dont know how to fix it.

So I thought maybe just alter the script to check if the player has a shirt object inside his character and if he doesn’t then create a shirt with Instance.new() or whatever. But I don’t know how to go about this.

Please help.

Script (RemoteEvent)

local events = game.ReplicatedStorage.Clothes:WaitForChild("Events")
local unifs = game.ReplicatedStorage.Clothes




events["2AD"].OnServerEvent:Connect(function(plr)
	plr.Character.Shirt.ShirtTemplate = unifs.Army["2ADShirt"].ShirtTemplate
	plr.Character.Pants.PantsTemplate = unifs.Army["2ADPants"].PantsTemplate
end)

If you know how to help, it’d be highly appreciated!

I’d recommend grabbing the actual value, like instead of using that use the rbx asset/id thing. I don’t think it will work but trial and error.

I would rather approach this by looking at Humanoid :ApplyDescription() and :GetAppliedDescription() methods to either get a character’s shirt, set a new one for a character, or even both. Only reason I would say so is because I have tried making character customization and encountered a similar issue where the specified shirt just wouldnt show up on the character.

applydescription documentation (useful)

I also recall someone on this forum having a similar problem before, but here is an example of how you would apply a shirt to a character (workspace dummy rig):

local id = 1240513975

local hum = game.Workspace.Rig.Humanoid

-- getting the description of the workspace rig
local testDescription: HumanoidDescription = hum:GetAppliedDescription() 

-- applied our modified description with a set shirt id
testDescription.Shirt = id
hum:ApplyDescription(testDescription) -- apply this description to the rig

You can probably see where I’m going with this, and look through the documentation on these methods to figure out your own way to get your specified shirt template(s) and apply it to a player’s character.

Hope this helps.