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

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

Asked by 4 years ago

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

Log in to vote
1
Answered by
Thetacah 712 Moderation Voter
4 years ago
Edited 4 years ago

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.

0
Thanks for responding that fast, and really good answer :) AndriusTheGreat 140 — 4y
Ad

Answer this question