|
| 18 Mar 2015 01:37 PM |
Let's say you have a local script that needs to wait for an object to load. It is first nature to use :WaitForChild(instance_name)
Let's also assume the object is going to be created from the server and put into the LocalPlayer. Knowing all of this, we can write:
local object = game.Players.LocalPlayer:WaitForChild("SomeInstanceName")
However, I've found that if you call WaitForChild from the CLIENT, and insert the object from the SERVER, :WaitForChild will not recognize the child, and will yield infinitely.
The only way you can fix this, I've found, is:
local object; repeat wait() object = game.Players.LocalPlayer:FindFirstChild("SomeInstanceName") until object
The solution is pretty inefficient and ugly. ROBLOX, could you try to fix this?
|
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 01:40 PM |
support that is pretty ineffective |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 18 Mar 2015 01:51 PM |
so many views so few replies |
|
|
| Report Abuse |
|
|
| |
|
|
| 18 Mar 2015 02:11 PM |
local function WaitForChild(Parent, Name) repeat wait() until Parent:FindFirstChild(Name) return Parent:FindFirstChild(Name) end
what to heck |
|
|
| Report Abuse |
|
|
Aluminize
|
  |
| Joined: 27 Sep 2014 |
| Total Posts: 209 |
|
| |
|
Q5C
|
  |
| Joined: 18 Sep 2012 |
| Total Posts: 8221 |
|
|
| 18 Mar 2015 02:13 PM |
go to scripters forum
we are too dumb for this |
|
|
| Report Abuse |
|
|
Kipec
|
  |
| Joined: 25 Nov 2010 |
| Total Posts: 10272 |
|
| |
|
|
| 18 Mar 2015 02:13 PM |
@undefined
that's inefficient and i don't wanna do that |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 02:14 PM |
And, if you're going to be using that function in multiple scripts, just use a ModuleScript.
what to heck |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 02:15 PM |
Yeah, but it looks better than what you came up with, AND it's what ROBLOX used before :WaitForChild was implemented.
what to heck |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 02:16 PM |
| I still think if ROBLOX is going to implement a method they should atleast get it to work. |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 02:23 PM |
Do you have FilteringEnabled?
what to heck |
|
|
| Report Abuse |
|
|
| |
|
Tripane
|
  |
| Joined: 03 Jun 2011 |
| Total Posts: 11432 |
|
|
| 18 Mar 2015 02:25 PM |
repeat wait() until hierarchy.object object = hierarchy.object
works for me |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 02:29 PM |
It's not a ROBLOX bug, it works fine for me.
Server: game.Players.PlayerAdded:connect(function(Player) wait(10) local s = Instance.new('IntValue', Player) s.Name = 'test' end)
Client: local p = game:GetService('Players').LocalPlayer local v = p:WaitForChild('test')
print(v)
> test
what to heck |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 02:35 PM |
I'm fairly sure, as a C++ programmer, that RBX Lua's WaitForChild is just as fast as C++. The only exception is that there's a minimum seconds for wait function, which is reasonable because it'll prevent the server or client crashing. Just take this for instance: repeat until death -- literally a crash script. 3 stupid words.
Technically there'd be a wait there, but let's say that there's no minimum seconds being enforced.
Anyway, to the point: I'm absolutely sure that the WaitForChild function's source code is this...
local object repeat wait() object = self:FindFirstChild(name) until object return object
self being the object, table, or even metatable it refers to, it's called Object Oriented style, i.e.
local Table = { }; function Table:Add(mixed) table.insert(self, mixed); end; |
|
|
| Report Abuse |
|
|