Char Clothing Problem

Hello Developers, I’m having a problem with my script. When I run the code its only detecting the shirt and not the pants and it’s weird. It’s not telling me why its not doing it for the pants. Please Help.

Code:

local NFolder = Instance.new('Folder', game.ReplicatedStorage)
NFolder.Name = 'CharDataBase'

game.Players.PlayerAdded:Connect(function(Player)
	local PFolder = Instance.new('Folder', NFolder)
	local SD = Instance.new('Shirt', PFolder)
	local PD = Instance.new('Pants', PFolder)
	PFolder.Name = Player.UserId
	SD.Name = 'Shirt'
	PD.Name = 'Pants'
	local FoundCharacter, CharacterModel = pcall(function()
		return game.Players:GetCharacterAppearanceAsync(Player.UserId)
	end)
	if CharacterModel:FindFirstChildOfClass('Shirt') ~= nil then
		if Player.UserId and PFolder.Name then
			SD.ShirtTemplate = CharacterModel.Shirt.ShirtTemplate
			Player.Character.Shirt.ShirtTemplate = SD.ShirtTemplate
		elseif CharacterModel:FindFirstChildOfClass('Pants') ~= nil then
		if Player.UserId == PFolder.Name then
			PD.PantsTemplate = CharacterModel.Pants.PantsTemplate
			Player.Character.Pants.PantsTemplate = PD.PantsTemplate
			end
		end
	end
end)

Most likely because it found the shirt then it stops, because elseif will only run if the statement above isn’t true.
Also, you forgot to put an end after Player.Character.Shirt.ShirtTemplate = SD.ShirtTemplate, because now elseif will only run if Player.UserId and PFolder.Name isn’t true.

Maybe

local NFolder = Instance.new("Folder", game.ReplicatedStorage)
NFolder.Name = "CharDataBase"

game.Players.PlayerAdded:Connect(function(Player)
	local PFolder = Instance.new('Folder', NFolder)
	local SD = Instance.new("Shirt", PFolder)
	local PD = Instance.new("Pants", PFolder)
	PFolder.Name = Player.UserId
	SD.Name = "Shirt"
	PD.Name = "Pants"
	local FoundCharacter, CharacterModel = pcall(function()
		return game.Players:GetCharacterAppearanceAsync(Player.UserId)
	end)
	if FoundCharacter then
		if CharacterModel:FindFirstChildOfClass("Shirt") and CharacterModel:FindFirstChildOfClass("Pants") then
			if Player.Character:FindFirstChildOfClass("Shirt") and Player.Character:FindFirstChildOfClass("Pants") then
				if Player.UserId and PFolder.Name then
					SD.ShirtTemplate = CharacterModel.Shirt.ShirtTemplate
					Player.Character.Shirt.ShirtTemplate = SD.ShirtTemplate
				end
				if CharacterModel:FindFirstChildOfClass("Pants") then
					if Player.UserId == PFolder.Name then
						PD.PantsTemplate = CharacterModel.Pants.PantsTemplate
						Player.Character.Pants.PantsTemplate = PD.PantsTemplate
					end
				end
			end
		end
	end
end)
1 Like

Thanks for the suggestion. Sadly it didn’t work :sad:

What exactly is the error it’s throwing at you?

Its not throwing any errors the problem is its not filling the pants ID with the normal character’s pants so thats why It’s not loading I think

It only looks for the pants if it finds the shirt, add a 2nd end to the shirt if statement:

if Player.Character:FindFirstChildOfClass("Shirt") and Player.Character:FindFirstChildOfClass("Pants") then
	if Player.UserId and PFolder.Name then
	SD.ShirtTemplate = CharacterModel.Shirt.ShirtTemplate
	Player.Character.Shirt.ShirtTemplate = SD.ShirtTemplate
	end
end
if CharacterModel:FindFirstChildOfClass("Pants") then
	if Player.UserId == PFolder.Name then
	PD.PantsTemplate = CharacterModel.Pants.PantsTemplate
		Player.Character.Pants.PantsTemplate = PD.PantsTemplate
	end
end

I found out how to fix it. I just had to change one of the statements because I kept it as == and forgot to change it to and

local NFolder = Instance.new('Folder', game.ReplicatedStorage)
NFolder.Name = 'CharDataBase'

game.Players.PlayerAdded:Connect(function(Player)
	local PFolder = Instance.new('Folder', NFolder)
	local SD = Instance.new('Shirt', PFolder)
	local PD = Instance.new('Pants', PFolder)
	PFolder.Name = Player.UserId
	SD.Name = 'Shirt'
	PD.Name = 'Pants'
	local FoundCharacter, CharacterModel = pcall(function()
		return game.Players:GetCharacterAppearanceAsync(Player.UserId)
	end)
	if CharacterModel:FindFirstChildOfClass('Shirt') ~= nil and CharacterModel:FindFirstChildOfClass('Pants') ~= nil then
		if Player.UserId and PFolder.Name then
			SD.ShirtTemplate = CharacterModel.Shirt.ShirtTemplate
			Player.Character.Shirt.ShirtTemplate = SD.ShirtTemplate
			PD.PantsTemplate = CharacterModel.Pants.PantsTemplate
			Player.Character.Pants.PantsTemplate = PD.PantsTemplate
		end
	end
end)

If player wears no pants that ain’t going to work (No clue why I deleted this one)

Then they will be ignored for being half nude.

Roblox automatically applies clothing to your avatar if you are missing clothes

Only if you’re using the same skin tone.

For some reason now my char can’t move

Right, but things like noob avatars could simply not want to wear pants, so ignoring the thing if they don’t have both things is straight up unjustified and possibly annoying to players.

I don’t think changing a shirt ID can cause a character to not move, it’s either other script or a roblox player bug

I know but you could just kick nude players for being naughty.

local NFolder = Instance.new('Folder', game.ReplicatedStorage)
NFolder.Name = 'CharDataBase'

game.Players.PlayerAdded:Connect(function(Player)
	local PFolder = Instance.new('Folder', NFolder)
	local SD = Instance.new('Shirt', PFolder)
	local PD = Instance.new('Pants', PFolder)
	PFolder.Name = Player.UserId
	SD.Name = 'Shirt'
	PD.Name = 'Pants'
	local FoundCharacter, CharacterModel = pcall(function()
		return game.Players:GetCharacterAppearanceAsync(Player.UserId)
	end)
	if CharacterModel:FindFirstChildOfClass('Shirt') ~= nil then
		if Player.UserId and PFolder.Name then
			SD.ShirtTemplate = CharacterModel.Shirt.ShirtTemplate
			Player.Character.Shirt.ShirtTemplate = SD.ShirtTemplate
		end
	end
	if CharacterModel:FindFirstChildOfClass('Pants') ~= nil then
		if Player.UserId == PFolder.Name then
			PD.PantsTemplate = CharacterModel.Pants.PantsTemplate
			Player.Character.Pants.PantsTemplate = PD.PantsTemplate
		end
	end
end)
1 Like
local NFolder = Instance.new('Folder', game.ReplicatedStorage)
NFolder.Name = 'CharDataBase'

game.Players.PlayerAdded:Connect(function(Player)
	local PFolder = Instance.new('Folder', NFolder)
	local SD = Instance.new('Shirt', PFolder)
	local PD = Instance.new('Pants', PFolder)
	PFolder.Name = Player.UserId
	SD.Name = 'Shirt'
	PD.Name = 'Pants'
	local FoundCharacter, CharacterModel = pcall(function()
		return game.Players:GetCharacterAppearanceAsync(Player.UserId)
	end)
	if CharacterModel:FindFirstChildOfClass('Shirt') ~= nil then
		if Player.UserId and PFolder.Name then
			SD.ShirtTemplate = CharacterModel.Shirt.ShirtTemplate
			Player.Character.Shirt.ShirtTemplate = SD.ShirtTemplate
		end
	end
	if CharacterModel:FindFirstChildOfClass('Pants') ~= nil then
		if Player.UserId == PFolder.Name then
			PD.PantsTemplate = CharacterModel.Pants.PantsTemplate
			Player.Character.Pants.PantsTemplate = PD.PantsTemplate
		end
	end
	if CharacterModel:FindFirstChildOfClass('ShirtGraphic') ~= nil then
		if Player.UserId == PFolder.Name then
			PD.TShirtGraphic = CharacterModel.ShirtGraphic.Graphic
			Player.Character.ShirtGraphic.Graphic = PD.TShirtGraphic
		end
	end
end)

Here’s added support for t-shirts.

My character can’t walk though