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

How to detect if a player has shirt/pants?

This is part of a character customization Gui.. I'm trying to make it so if a shirt and pants are both detected, then a message pops up. If it doesn't detect both, then a different one is displayed. When run, the "message1" frame shows up even if the character doesn't have a 'Shirt' or 'Pants' item on them. (The shirt and pants were completely removed when they entered, so it's not that the texture just isn't set.) Thanks!

function C()
if game.Players.LocalPlayer.Character:FindFirstChild("Shirt") and game.Players.LocalPlayer.Character:FindFirstChild("Pants")then
	script.Parent.Parent.message1.Visible = true
	wait(5)
	script.Parent.Parent.message1.Visible = true
else
	script.Parent.Parent.message.Visible = true
	wait(5)
	script.Parent.Parent.message.Visible = true
end
end
script.Parent.MouseButton1Click:connect(C)

1 answer

-- Set this in a localscript inside of the button.
local character = game.Players.LocalPlayer.Character
local scheck = false
local pcheck = false

script.Parent.MouseButton1Down:connect(function()
	for i,v in pairs(character) do
		if v:IsA("Shirt") then scheck = true end
		if v:IsA("Pants") then pcheck = true end
	end
	if scheck and pcheck then
		script.Parent.Parent.message1.Visible = true
		wait(5)
		script.Parent.Parent.message1.Visible = false -- In the example you had this to true, assuming you meant false.
	else
		script.Parent.Parent.message.Visible = true
		wait(5)
		script.Parent.Parent.message.Visible = false -- In the example you had this set to true, assuming you meant false.
	end
end)

2 comments

0

Thanks for the response! However, when I ran it, I got this error: "Players.Player.PlayerGui.customizeGui.maleinterface.Play.male:6: bad argument #1 to 'pairs' (table expected, got Object)" for line 6. Any ideas as to how to fix that? Thanks again!

0

Never mind, just added ":GetChildren()" after game.Players.LocalPlayer.Character. Thanks!

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