Unexplainable Script Yielding?

Context
Following the recent development of my yet to be released admin pane, I decided to make installing the admin panel as convenient as possible, by having it automatically fetch and set up the latest version of it (via toolbox).

This advancement seemed to be all well, until I started getting infinite yielding messages from one of my most essential scripts.

 Infinite yield possible on 'Players.JeffTheEpicRobloxian:WaitForChild("Verified")

After looking further into the issue, I found that the issue was linked to the script which was supposed to instance the value, and I found it was yielding here:

local commandsModule = require(game:GetService("ServerStorage"):WaitForChild("commands"))

Yes, you might go:
Oh Well, are you certain you have a module within server storage called ‘commands’?
Yes I am. I’ve triple checked. and I’ve been marvelling at the complexity of such a simple issue. Am I missing something? Have I messed up? I don’t know, but I know for certain that when the player joins the game, they the module is put into serverstorage, along with its associate scripts.

So, I’ve explained… What could be the cause?
If you have any further enquiries, here is the full uncut code for both the main handler script and the autoplace/updater script:

Auto Updater/Mover Script

local InsertService = game:GetService("InsertService")
print("Script is running...")
local JAdminId = 6408603034
local function UnpackModel(Model)
	for indexChild, Child in pairs(Model:GetChildren()) do
		Child.Parent = Model.Parent
	end
	Model:Destroy()
end
local insertedModel
local success, errormessage = pcall(function()
	local latestVersion = InsertService:GetLatestAssetVersionAsync(JAdminId)
	insertedModel = InsertService:LoadAssetVersion(latestVersion)
end)
if success then
	local actualModel = insertedModel["J+ Admin"]
	if actualModel then
		actualModel["RepStorage"].Parent = game:GetService("ReplicatedStorage")
		actualModel["ServerScriptService"].Parent = game:GetService("ServerScriptService")
		actualModel["ServerStorage"].Parent = game:GetService("ServerStorage")
		actualModel["StarterGui"].Parent = game:GetService("StarterGui")
		print("Parented Models")
		UnpackModel(game.ReplicatedStorage["RepStorage"])
		UnpackModel(game.ServerScriptService["ServerScriptService"])
		UnpackModel(game.ServerStorage["ServerStorage"])
		UnpackModel(game.StarterGui["StarterGui"])
	end
	print("Done!")
	
	script.Parent:Destroy()
else
	warn(errormessage)
end

Main Handler Relevant Code:

local commandsModule = require(game:GetService("ServerStorage"):WaitForChild("commands")) --yeilding here
local modModule = require(game.ServerStorage:WaitForChild("moderationDataCommands"))
local ChatLogsTable = {}
local httpService = game:GetService("HttpService")
local coolDownAmount = 360 --One request from the player 6 minutes
local textService = game:GetService("TextService")
local groupId = 7895196
local requiredRank = 253

Why are you using WaitForChild in a server script?

1 Like

One way you could prevent the infinite yield is through specifying WaitForChild’s 2nd parameter which is the time it lasts to try and wait for a child before stopping, called timeOut

local commandsModule = require(game:GetService("ServerStorage"):WaitForChild("commands", 10)) --Tries to wait for the child for 10 seconds before progressing if it couldn't find it

Or alternatively, you can just use FindFirstChild instead

local commandsModule = require(game:GetService("ServerStorage"):FindFirstChild("commands"))
1 Like