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: Which is more efficient

Previous Thread :: Next Thread 
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
27 May 2013 02:15 PM
repeat wait(0) until Game.Workspace:FindFirstChild("Model")

OR

while not Game.Workspace:FindFirstChild("Model") do wait(0) end
Report Abuse
nairod7 is not online. nairod7
Joined: 26 Mar 2010
Total Posts: 869
27 May 2013 02:16 PM
repeat wait(0) until Game.Workspace:FindFirstChild("Model")

-> It will wait(0) and after loop check if Game.Workspace:FindFirstChild("Model") returns true.

while not Game.Workspace:FindFirstChild("Model") do wait(0) end

-> Verify before if the model exists or not before waiting.


In that case, I would use a ChildAdded event, but it depend of your script though.
Report Abuse
Cupkle is not online. Cupkle
Joined: 18 Jun 2012
Total Posts: 180
27 May 2013 02:17 PM
workspace:WaitForChild('Model')
Report Abuse
nairod7 is not online. nairod7
Joined: 26 Mar 2010
Total Posts: 869
27 May 2013 02:19 PM
:o

That's a function they've added recently?
Report Abuse
Cupkle is not online. Cupkle
Joined: 18 Jun 2012
Total Posts: 180
27 May 2013 02:24 PM
Yeah, pretty useful.

http://wiki.roblox.com/index.php/API:Instance/WaitForChild
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
27 May 2013 02:25 PM
What if, it's adding to lighting?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
27 May 2013 02:26 PM
=D
Seems useful
Report Abuse
uyjulian is not online. uyjulian
Joined: 29 Nov 2012
Total Posts: 1214
27 May 2013 02:41 PM
Yep
it's useful :-)
Report Abuse
RaidenJPN is not online. RaidenJPN
Joined: 22 May 2013
Total Posts: 6920
27 May 2013 02:43 PM
When did they add that?
Report Abuse
nairod7 is not online. nairod7
Joined: 26 Mar 2010
Total Posts: 869
27 May 2013 02:56 PM
That's why a proper change log is needed!
Report Abuse
RaidenJPN is not online. RaidenJPN
Joined: 22 May 2013
Total Posts: 6920
27 May 2013 03:42 PM
@Nairod,

Let's blame all the wiki writers for not making one.
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
27 May 2013 03:46 PM
@RaidenJPN,

http://wiki.roblox.com/index.php/WaitForChild
Your not very good at this.
Report Abuse
nairod7 is not online. nairod7
Joined: 26 Mar 2010
Total Posts: 869
27 May 2013 03:52 PM
Why the wiki writers? They don't make those new functions, they do a good work actually. I'd blame developers instead.
Report Abuse
RaidenJPN is not online. RaidenJPN
Joined: 22 May 2013
Total Posts: 6920
27 May 2013 03:59 PM
@Flu,

I never said that there was no wiki post on the new method.

I said that we should blame them for the lack of development log, but then Nairod suggested a better idea.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
27 May 2013 04:10 PM
While loop should be used when waiting for stuff to load like that. But WaitForChild is better.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
27 May 2013 05:31 PM
Ignoring the fact that you should use WaitForChild in this case, the best way is something like this:

while not Game.Workspace:FindFirstChild("Model") do Game.Workspace.ChildAdded:wait() end

Or if you know it's not already there, even cooler:
repeat until Game.Workspace.ChildAdded:wait().Name == "Model"

Which will wait until a child actually arrives before checking again.

I use this approach a lot in gear to wait for a certain point in an animation to be reached:
...
repeat until animationTrack.KeyframeReached:wait() == 'FrameImWaitingFor'
...
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
27 May 2013 05:32 PM
That is genius ^
Report Abuse
TheOneSwordfighter is not online. TheOneSwordfighter
Joined: 18 Feb 2013
Total Posts: 212
27 May 2013 05:36 PM
You've given us some good insights in a short time, thanks.
Report Abuse
UnBuild is not online. UnBuild
Joined: 22 Mar 2013
Total Posts: 3233
27 May 2013 05:47 PM
Is everyone just going to ignore that WaitForChild doesn't work?
Report Abuse
18cwatford is not online. 18cwatford
Joined: 08 Oct 2009
Total Posts: 5410
27 May 2013 05:50 PM
It works. It _should_ and did/does.
Report Abuse
UnBuild is not online. UnBuild
Joined: 22 Mar 2013
Total Posts: 3233
27 May 2013 05:53 PM
Well I was trying to use it like literally 5 minutes ago



Game.Players:WaitForChild("PlayerGui")
print("Has gui")


Did nothing, even if I removed the PlayerGui and put a new one in


And if I tried to do something with the PlayerGui without waiting for it, it errored saying it wasn't a valid member.
Report Abuse
18cwatford is not online. 18cwatford
Joined: 08 Oct 2009
Total Posts: 5410
27 May 2013 05:55 PM
...Thats cause it'd only go once a object with the name "PlayerGui" has been added to game.Players...

game.Players.PlayerAdded:connect(function(p)
p:WaitForChild("PlayerGui")
print(p.Name.." has playergui")
end)
Report Abuse
Parthax is not online. Parthax
Joined: 27 Apr 2011
Total Posts: 6941
27 May 2013 05:55 PM
WaitForChild has been around for quite some time

object:WaitForChild(name)
waits for a child with the name [name] inside object.
Report Abuse
18cwatford is not online. 18cwatford
Joined: 08 Oct 2009
Total Posts: 5410
27 May 2013 05:56 PM
Now we need WaitForDescendant
Report Abuse
UnBuild is not online. UnBuild
Joined: 22 Mar 2013
Total Posts: 3233
27 May 2013 05:57 PM
@18
That was a typo, When I tried it I used it correctly, still didn't work
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