"Infinite yield possible" warn even though the script works

I have written a few ModuleScripts (classes and helper stuff) and for a normal script to work, i require said modules at the beginning of the script, like this:

local Modules = game:GetService("ServerScriptService"):WaitForChild("Modules")
local Generator = require(Modules.Game.Generator)
local Map = require(Modules.Game.Map)

After which i have a function that makes use of the Map module. The code works and runs perfectly well, but after a few seconds i still get the warning: Infinite yield possible on 'ServerScriptService:WaitForChild("Modules")'.

Is there any way to get rid of this warning? Any ideas what could be causing it?

local Modules = game:GetService("ServerScriptService"):WaitForChild("Modules", math.huge)

Oh, didn’t know that existed! Thanks, I’ll use this for now, but is there a proper solution to fix what seems to be a roblox bug?

Edit: apparently the error still shows after adding the parameter.

Code is probably seeing a case where Modules does not exist in the ServerScriptService. Are you replicating it into the ServerScriptService as a parent through another script?

just write it like this

local ServerScriptService = game:GetService("ServerScriptService")
local Modules = ServerScriptService:WaitForChild("Modules")

If its on the client, i recommend moving modules to Replicated storage

local ReplicatedStorage = game:GetService("ReplicatedStorage ")
local Modules = ReplicatedStorage:WaitForChild("Modules")

I found the issue, apparently I had blindly pasted that ServerScriptService require into a LocalScript, no wonder it didn’t work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.