Nikilis
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 949 |
|
|
| 03 Sep 2013 06:38 AM |
> if player.Character.Torso ~= nil then > Torso is not a valid member of model
wat |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2013 06:39 AM |
| if player.Character:FindFirstChild("Torso") ~= nil |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2013 06:43 AM |
"if player.Character.Torso ~= nil then" "if" Lua: K is an if statement "player.Character.Torso" Lua: Dafudge is that? Dunno, Just going to stop here.
"if player.Character:FindFirstChild("Torso") ~= nil" "if" Lua: K is an if statement "player.Character:FindFirstChild("Torso")" Lua:K didn`t find it so it`s nil "~= nil" Lua:K it`s nil, Gonna look for an end now |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 03 Sep 2013 06:48 AM |
Oh God, why would you '~= nil' on a Boolean return?
if (player.Character:findFIrstChild('Torso')) then |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2013 08:58 AM |
| Blame yourself before you blame the computer |
|
|
| Report Abuse |
|
|
Trioxide
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
|
| 03 Sep 2013 09:00 AM |
It didn't exist. duh. + what cm32 said because he likes to be called cm32
TRIOXIDE TRIOXIDE TRIOXIDE TRIOXIDE TRIOXIDE TRIOXIDE |
|
|
| Report Abuse |
|
|
Nikilis
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 949 |
|
|
| 03 Sep 2013 11:01 AM |
| But it works on other things? The only reason I did it like that instead of using FindFirstChild() is because what if their character is gone? Whateva I'll just do it the annoying inefficient way. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2013 11:04 AM |
:findFirstChild is always more efficient for checking stuff. If you want to get even more efficient, do it like this :D.
if player:findFirstChild("Character"):findFirstChild("Torso") then
LOL!! This is more efficient in case the character is gone as you said. |
|
|
| Report Abuse |
|
|
Nikilis
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 949 |
|
|
| 03 Sep 2013 11:05 AM |
| Isn't character a property of Player and not a child though? |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2013 11:51 AM |
Yes, but Torso is not a property. You're trying to access 'Torso' in the Character, and if Torso doesn't exist, then you're gonna get an error since you're trying to reference something that doesn't exist.
if (player.Character:FindFirstChild("Torso")) then ... end |
|
|
| Report Abuse |
|
|
Nikilis
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 949 |
|
|
| 03 Sep 2013 01:48 PM |
| Yeah, I know what I have to do, it's just ugly. I want to check if all three of them are not nil in one clean line but that's not gonna happen so whateva. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2013 02:00 PM |
| if (player.Character and player.Character:FindFirstChild("Torso")) then ... |
|
|
| Report Abuse |
|
|
Nikilis
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 949 |
|
|
| 03 Sep 2013 02:04 PM |
| Right, cuz player.Character is a property; but I think I'll just check for Torso, I've had no character problems, it's just Torsos are disappearing for some reason. |
|
|
| Report Abuse |
|
|
Ri1es
|
  |
| Joined: 19 Mar 2011 |
| Total Posts: 108 |
|
|
| 03 Sep 2013 02:35 PM |
The reason you have had no problem with .Character is because it is a property of the Player object, which equals the player's character.
E.g. "if player.Character ~= nil then" would work because Character is not a child of the player but a property. However "player:FindFirstChild("Character")" would return nil because there is no child called Character in the Player object, but it would return an object if there was a child with the name of "Character".
-Ri1es |
|
|
| Report Abuse |
|
|
Ri1es
|
  |
| Joined: 19 Mar 2011 |
| Total Posts: 108 |
|
|
| 03 Sep 2013 02:39 PM |
Also Absurdism,
http://wiki.roblox.com/index.php/API:Instance/FindFirstChild
:FindFirstChild() does not have a Boolean return, it has an Instance return.
-Ri1es |
|
|
| Report Abuse |
|
|
janthran2
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 84 |
|
|
| 03 Sep 2013 02:44 PM |
| Well if you knew how to script you wouldn't have a problem |
|
|
| Report Abuse |
|
|
Nikilis
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 949 |
|
|
| 03 Sep 2013 03:28 PM |
| I know how to script, and I don't have a problem... I was questioning syntax that really shouldn't do what it is doing. I know that Player.Character is a property, which means it can be nil, and I know that you can't use FindFirstChild("Character"). |
|
|
| Report Abuse |
|
|
janthran2
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 84 |
|
| |
|
|
| 03 Sep 2013 03:34 PM |
why use: if player.Character:FindFirstChild("Torso") ~= nil
I like this more: if player.Character:FindFirstChild("Torso") then |
|
|
| Report Abuse |
|
|
Brycemlns
|
  |
| Joined: 28 Jan 2008 |
| Total Posts: 216 |
|
|
| 03 Sep 2013 03:52 PM |
| I was stuck on this the other day as well OP, you're not alone. |
|
|
| Report Abuse |
|
|
janthran2
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 84 |
|
|
| 03 Sep 2013 03:57 PM |
You tried to reference something that doesn't exist that's stupid |
|
|
| Report Abuse |
|
|
Nikilis
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 949 |
|
|
| 03 Sep 2013 04:58 PM |
@janthran2
I wasn't plain wrong at all; I was right.
player.Character.Torso ~= nil should honestly check if player, Character, and Torso are not nil. It should check if the entire path is not nil. If player.Character.Torso does not lead to anything, it just return as false. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2013 04:59 PM |
| No, it reads you assuming "Torso" is part of the character before '~= nil', that's why you use FindFirstChild(). |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2013 05:01 PM |
"player.Character.Torso ~= nil should honestly check if player, Character, and Torso are not nil. It should check if the entire path is not nil. If player.Character.Torso does not lead to anything, it just return as false."
That makes no sense. Why would it if you can do it manually anyway. If you refer to an object in a table, why should it automatically assume the table the object is in wouldnt exist? You refer to it, you need to be sure, not Lua. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2013 05:03 PM |
| Just use a pcall or a ypcall and call it good without the if for the character torso |
|
|
| Report Abuse |
|
|