generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Is the part passed to a Touch callback guaranteed to have a parent?

Previous Thread :: Next Thread 
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
16 Jul 2011 09:08 AM
I've been looking over the wiki, and seen a lot of code like this:

    part.Touched:connect(function(hit)
        if hit.Parent then
            --Do stuff
        end
    end

Is the check on hit.Parent strictly necessary? Surely in order to collide, the part must be a descendant of workspace, so therefore must have a non-nil parent.

Should I be doing this in my code as well, or should I remove these statements from the wiki?
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
16 Jul 2011 09:10 AM
Yes, it's necessary.

Things like bullets remove themselves when their Touched event is fired, so when the other brick's Touched event is fired the "hit" argument's parents can be nil.

Lots of things don't do this check so they can be broken by being shot at.
Report Abuse
bunnybunn263 is not online. bunnybunn263
Joined: 12 Sep 2007
Total Posts: 974
16 Jul 2011 09:12 AM
I've made hundreds of Touched() scripts before. You don't really need a 'if hit.Parent then' statement, because, yes, the Parent would have to be non-nil for a Touched() function.
Report Abuse
bunnybunn263 is not online. bunnybunn263
Joined: 12 Sep 2007
Total Posts: 974
16 Jul 2011 09:13 AM
@sncplay42
Well, except, it can be important for things like that. >.>
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
16 Jul 2011 09:44 AM
"Lots of things ... can be broken by being shot at" - sounds like a feature.

Presumably it's still safe to use the "hit" argument, even though it has been removed? Or is it invalid to work with a :remove()d object?
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
16 Jul 2011 09:45 AM
It's still valid, its parent will just be nil and anything that was in it will also have been removed.
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
16 Jul 2011 10:13 AM
So its not like working with a finalized object in C++ then
Report Abuse
Razer100 is not online. Razer100
Joined: 28 Aug 2009
Total Posts: 8066
16 Jul 2011 10:15 AM
Everything on the wiki has not been implemented, stay away from it.

very misleading
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
16 Jul 2011 10:15 AM
@Razer

what?
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
16 Jul 2011 10:17 AM
BaseParts haven't been implemented, apparently. Judging by Razer's post.
Report Abuse
thegenius is not online. thegenius
Joined: 03 Oct 2008
Total Posts: 3838
16 Jul 2011 10:19 AM
Nothing is actually being physically represented?

My life has been changed forever...
Report Abuse
TaslemGuy is not online. TaslemGuy
Joined: 10 Jun 2009
Total Posts: 12174
16 Jul 2011 10:24 AM
Yes, you do.

"Bullets" often have the Parent of nil when they hit an object.
Report Abuse
Razer100 is not online. Razer100
Joined: 28 Aug 2009
Total Posts: 8066
16 Jul 2011 10:25 AM
@Blocco and Taco.


ALOT of things are on the wiki that are not implemented
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
16 Jul 2011 10:27 AM
@Razer: You've just created a dependent clause. Would you like to finish it off with an independent clause.
Report Abuse
Razer100 is not online. Razer100
Joined: 28 Aug 2009
Total Posts: 8066
16 Jul 2011 10:31 AM
Look, you know yourself what's there and what's here.
Report Abuse
popinman322 is not online. popinman322
Joined: 04 Mar 2009
Total Posts: 5184
16 Jul 2011 10:36 AM
PrismPart, StoppedTouching event, ParallelRampPart... Oh, you _DIDN'T_ want me to start listing things... kk
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
16 Jul 2011 11:08 AM
[ Content Deleted ]
Report Abuse
Razer100 is not online. Razer100
Joined: 28 Aug 2009
Total Posts: 8066
16 Jul 2011 11:23 AM
I'm not an idiot D:


QQ
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
16 Jul 2011 11:30 AM
[ Content Deleted ]
Report Abuse
LocalChum is not online. LocalChum
Joined: 04 Mar 2011
Total Posts: 6906
16 Jul 2011 11:36 AM
Am I an idiot? D:
Report Abuse
Razer100 is not online. Razer100
Joined: 28 Aug 2009
Total Posts: 8066
16 Jul 2011 11:41 AM
Implying I'm southern.








>Grow up
>I'm glad to know your ability's on an online game give you the power to say I'm an "idiot"
Report Abuse
lucas668 is not online. lucas668
Joined: 18 Jun 2008
Total Posts: 6183
16 Jul 2011 12:15 PM
Razer is just jelly.


Oh yeah, and you don't need to check for the parent unless you got guns or something like it at the place you are scripting in. Otherwise, if you don't perform the check and the part is shot, this happens:


if part.Parent:FindFirstChild("Humanoid") then

- ERROR YOU NOOB PARENT IS NIL
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image