i’m going to ask for clarification, you want it to do shirt:destroy() only if a shirt is detected, and skip this action if there is no shirt detected?
local shirt = script.Parent:WaitForChild("Shirt")
if shirt then -- if a shirt is found
shirt:Destroy() -- destroys it
else -- if no shirt is found
end -- script ends
Your script is correct however there’s no reason to end with “)” that simply causes a syntax error, since you’re not closing correctly.
I’d suggest just removing the final point and it should be all good from there.
local _, Character = nil, script.Parent or script.AncestryChanged:Wait()
local Shirt = Character:FindFirstChildOfClass("Shirt")
if Shirt then
print(Character.Name.." is wearing a shirt!")
Shirt:Destroy()
end
This is working for me (local script inside StarterCharacterScripts).
To add to this, to ensure the shirt has loaded when the script runs, you can try waiting for the player appearance to load:
--script inside StarterCharacterScripts
local Character = script.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
if not Player:HasAppearanceLoaded() then
Player.CharacterAppearanceLoaded:Wait()
end
local Shirt = Character:FindFirstChildWhichIsA("Shirt")
if Shirt then
print("shirt found, and destroyed")
Shirt:Destroy()
else
print(Character.Name.." isn't wearing a shirt")
end