Trying to put clothes on a player if they don't have any on

i have a script that adds clothes 2 a player when they join so this works:

		local shirt = c:FindFirstChildOfClass("Shirt")
		local pants = c:FindFirstChildOfClass("Pants")
		
		shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=12434115033"
		pants.PantsTemplate = "http://www.roblox.com/asset/?id=12434143876"

however, if they dont have shirt/pants or shirt AND pants on then it’ll make a new shirt/pants n yeah but i cant get it to work. i appreciate any help ty!

script:

game.Players.PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(c)
		
		local shirt = c:FindFirstChildOfClass("Shirt")
		local pants = c:FindFirstChildOfClass("Pants")
		
		shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=12434115033"
		pants.PantsTemplate = "http://www.roblox.com/asset/?id=12434143876"
		
		if shirt == nil then
			local newShirt = Instance.new("Shirt", c)
			newShirt.Name = "newShirt"
			newShirt.ShirtTemplate = "http://www.roblox.com/asset/?id=12434115033"
		end
		
		if pants == nil then
			local newPants = Instance.new("Pants",c)
			newPants.Name = "newPants"
			newPants.PantsTemplate = "http://www.roblox.com/asset/?id=12434143876"
		end
	end)
end)

i somehow got it by messing around

this is the solution for those who want something like this:

game.Players.PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(c)
		
		local shirt = c:FindFirstChildOfClass("Shirt")
		local pants = c:FindFirstChildOfClass("Pants")
		
		if shirt and pants then
		shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=12434115033"
		pants.PantsTemplate = "http://www.roblox.com/asset/?id=12434143876"
	
		
		elseif shirt and not pants then
			local noPants = Instance.new("Pants",c)
			noPants.Name = "noPants"
			noPants.PantsTemplate = "http://www.roblox.com/asset/?id=12434143876"
			shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=12434115033"
			
		elseif pants and not shirt then
			local noShirt = Instance.new("Shirt", c)
			noShirt.Name = "newShirt"
			noShirt.ShirtTemplate = "http://www.roblox.com/asset/?id=12434115033"
			pants.PantsTemplate = "http://www.roblox.com/asset/?id=12434143876"
		
else
			local newShirt = Instance.new("Shirt", c)
			newShirt.Name = "newShirt"
			newShirt.ShirtTemplate = "http://www.roblox.com/asset/?id=12434115033"

			local newPants = Instance.new("Pants",c)
			newPants.Name = "newPants"
			newPants.PantsTemplate = "http://www.roblox.com/asset/?id=12434143876"
		end
	end)
end)

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