Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why it can't detect if a player have Shirt or Pants?

What i want to do is to check when a player if he or she have a Shirt or Pants

game.Players.PlayerAdded:Connect(function(plr)
	
	
	plr.CharacterAdded:Connect(function(char)
		wait(2)
		
		if char.Pants == nil or char.Pants:IsA("Pants") then
			print("Pants")
		elseif not char.Shirt then
			print("No Pants")
		end
		if char.Shirt == nil or char.Pants:IsA("Shirt") then
			print("Shirt")
		elseif not char.Shirt then
			print("No Shirt")
		end
	end)
end)

1 answer

You need to wait for the pants and shirt because when the player joins the character model is made then the pants and shirt and everything else is added after so you have to wait for them.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		wait()
		if character:FindFirstChild("Pants") then
			print("pants")
		else
			print("no pants")
		end

		if character:FindFirstChild("Shirt") then
			print("shirt")
		else
			print("no shirt")
		end
	end)
end)

Here's an updated version. I used "wait()" which pauses the script for a short amount of time to give time for the pants and shirt to be added to the character. I tested it and it should work.

1 comment

0

Also you can use "FindFirstChildWhichIsA" which will find a object which is a certain object type. https://developer.roblox.com/en-us/api-reference/function/Instance/FindFirstChildWhichIsA

This discussion is preserved as it was. New answers, comments, and votes are closed.