so i am trying to remove the shirt of an player (if he wears one) and the remove it but if i ask if the player has a shirt and he does not the if statement still runs
1 | if char.Shirt then |
2 | char.Shirt:remove() |
3 | end |
If you are asking the player if they want to remove their shirt, but they do not have it in the first place, you need to use :FindFirstChild
, which returns nil if the shirt does not exist, and references the shirt itself it exists.
Your original attempt does not work if the player does not have shirt because it is attempting to find something that does not exist in the if statement itself (not a valid member of).
1 | local shirt = char:FindFirstChild( "Shirt" ) |
2 | --if shirt exists, destroy it. |
3 | if shirt then |
4 | --Use Destroy since :remove is deprecated. |
5 | shirt:Destroy() |
6 | end |
do not use :remove()
use :Destroy()
cough it's desperated
1 | game.Players.PlayerAdded:Connect( function (player) --the player is added |
2 | local char = player.Character --the character |
3 | if char.Shirt then |
4 | char.Shirt:Destroy() |
5 | end |
6 | end ) |