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
if char.Shirt then
char.Shirt:remove()
end
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
if char.Shirt then
char.Shirt:remove()
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).
local shirt = char:FindFirstChild("Shirt")
--if shirt exists, destroy it.
if shirt then
--Use Destroy since :remove is deprecated.
shirt:Destroy()
end
do not use :remove() use :Destroy() cough it's desperated
game.Players.PlayerAdded:Connect(function(player)--the player is added
local char = player.Character --the character
if char.Shirt then
char.Shirt:Destroy()
end
end)
yes but its still the same problem on the player is no shirt but the if statement still runs and stops the script
ok fixed
Not "desperated", Deprecated.
"desperated"? You guys are making basic Lua look like rocket science...
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
thanks works now and i understand i have to try to put it with FindFirstChild in a variable and if does not exist it will turn fals Thanks
why did u downvote mine? Explain.
I didn't.