Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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.

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 Optimalpokemon123 37 — 4y
Ad

Answer this question