hello i find myself using alot of waitforchild's is there a better way to do this?
Example
workspace:WaitForChild("model"):WaitForChild("brick"):WaitForChild("ClickDetector")
it seems super inefficient to me any better way of doing this?
Try this:
repeat wait(0.01) until workspace:FindFirstChild("model") repeat wait(0.01) until workspace.model:FindFirstChild("brick") repeat wait(0.01) until workspace.model.brick:FindFirstChild("ClickDetector")
Just gonna leave this here in-case someone else stumbles upon it and is confused since the accepted answer is actually less efficient. Using the WaitForChild() function is completely fine and is the best possible way to wait for an instance. However, there are ways you can write it so that there are less of the function.
For example, say we had a Model class named "X" in Workspace. Inside of X, we also have A and B, which we need for our code. Instead of looking for them individually, we can look for "X" first, and then locate A and B from X's index. It would look something like this:
--// Variables //-- local X = workspace:WaitForChild("X"); local A,B = X:WaitForChild("A"), X:WaitForChild("B");