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

Cannot find child in FilteringEnabled?

Asked by
Dummiez 360 Moderation Voter
10 years ago

When I add a StringValue with a BoolValue inside in the Workspace, this function is supposed to run in a LocalScript inside the PlayerGui.

Workspace.ChildAdded:connect(function(child)
if child:IsA("StringValue") then
    print(child.Name)
    print(child:FindFirstChild("BoolValue").Value)  
end
end)

It doesn't seem to be working when I set the game to Workspace.FilteringEnabled, and only finds the child, and returns BoolValue as nil (It does work, however when it is not in FilteringEnabled).

UPDATE: I managed to come up with a alternative for now, not sure if there is a simpler one. I added an ObjectValue just to simply store the StringValues and BoolValues so DescendantAdded will only check the ObjectValue.

Workspace.ObjectValue.DescendantAdded:connect(function(child)
if child.Parent.Name == "StringValue" then
    print(child.Value) -- Prints the value of BoolValue
    print(child.Parent.Value) -- Prints the value of StringValue
end
end)

I'm not sure why this works in FilteringEnabled if you get the instance you want in the parent's instance.

1 answer

Log in to vote
0
Answered by
Destrings 406 Moderation Voter
10 years ago

That's because the instance may have been streamed out. From the wiki

Because this feature changes the way parts are sent to the client, scripters will have to keep in mind that objects referenced in local Lua scripts might have not arrived or have been streamed out.

Read more at http://wiki.roblox.com/index.php/Network_streaming

0
I think you're referring to StreamingEnabled. FilteringEnabled basically sets the PlayerGui as client-sided only. Dummiez 360 — 10y
0
Yes, my bad. I was totally unaware of that feature. So much time without reading the API. So that basically disables clients changes replicating to the server. Maybe FindFirstChild needs to write on the server for it to work. I'm going to try to reproduce the error and try to fix it. Destrings 406 — 10y
0
I got to work by using DescendantAdded and getting the BoolValue first and getting the String by parenting. Not sure why it works like that though. Dummiez 360 — 10y
0
Yeah. It has something to do with the client reading the value. I reproduced the error. When tried the same script on the server it worked just fine. Destrings 406 — 10y
0
Fixed it replacing FindFirstChild with WaitForChild. My guess is that with FilteringEnabled there's a delay added in the server replicating the Instance to the client maybe its doing some check. So we were trying to read a value that wasn't replicated yet. Destrings 406 — 10y
Ad

Answer this question