Search code examples
moduleluarobloxluau

Roblox - Infinite yield possible on 'ReplicatedStorage.bpg.packages:WaitForChild("Instance")'


I have been working on a basic Roblox script where I require every moduleScript in a folder! I managed to snatch a code snippet from the DevForums, but it didn't work as expected.

My code is as follows:

21 | for _, x in pairs(packages:GetChildren()) do
22 |    packageHandler[x] = require(script.Parent.packages:WaitForChild(x))
23 |    if not packageHandler[x] and logEnabled then 
24 |          print("Could not find package "..x.."! Are you certain it exists?") 
25 |    end
26 | end
27 |
28 | return packageHandler

When required via. my Parent script (module script), it returns a warning on the first module script of which it tries to require:

Infinite yield possible on 'ReplicatedStorage.bpg.packages:WaitForChild("Instance")'

This warning occurs on line 22!


Solution

  • I needed to require(x) as x is an instance and I cant use :WaitForChild(x) on an instance (according to LukaDev).

    Answered!