Answered by
4 years ago Edited 4 years ago
To ensure your part is located, we will design a function that will use a rigorous search, so to speak.
Firstly, we'll allow this function to use :WaitForChild() to account for Client latency. We'll allow a timeout of five seconds—the internal leniency window before a yield-warn—to locate the Instance. If this limit is surpassed while no Instance is found, we'll engage a .ChildAdded signal to listen for new Instances, and to check whether said newly added Instance is the one we were originally looking for.
LocalScript; StarterCharacterScripts.
02 | local Player = game:GetService( "Players" ) |
07 | local Character = Player.Character or Player.CharacterAdded:Wait() |
14 | local function CheckForPart() |
15 | local Part = Character:WaitForChild( "Glasses1" , 1 ) |
21 | ChildAdded:Disconnect() |
24 | if ( not ChildAdded) then |
25 | ChildAdded = Character.ChildAdded:Connect(CheckForPart) |