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

How to detect if a player has shirt/pants?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago
-- 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)
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! AmericanDev 10 — 8y
0
Never mind, just added ":GetChildren()" after game.Players.LocalPlayer.Character. Thanks! AmericanDev 10 — 8y
Ad

Answer this question