Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can the if statement work without any conditions if yes then how?

I recently stumbled upon this line of code.

if player.Character and player.Character:FindFirstChild('Torso') then

I got confused because if should handle a certain condition, but in this case, I can't see any conditions that the if statement should be looking for. I have searched the web for answers but none of them was able to answer my question.

1 answer

✓ Accepted answer

The if statement in your post is checking:

That player.Character is not equal to nil

That the torso is not equal to nil

If those two conditions are met, this means both the character, and the torso have loaded and are present.

If you were to put the following in a LocalScript inside the Backpack, it would print "No character found" since the Character would have not loaded yet before the script ran:

local plr = game.Players.LocalPlayer
local char = plr.Character

if char then
	print("Character found")
else
	print("No character found")
end

Same idea applies for your if statement.

1 comment

0

Thanks for responding that fast, and really good answer :)

This discussion is preserved as it was. New answers, comments, and votes are closed.