Infinite Yield while requiring a ServerScriptService folder

In a module script called “ObjectDataManager” I have information about tools and objects in my game that I can just look up from the module script.
It looks like this:

local DataStore = {}

DataStore.Gems = {
	{Name = "Diamond", Color = Color3.new(0.32, 0.76, 0.65), Value = 1000, Hardness = 10, SizeMultiplier = 1.2},
	{...},
}

DataStore.Pickaxes = {
	{Name = "RustyPickaxe", Value = 10, Hardness = 1},
	{...}
}

function DataStore:GetPickaxes()
	local Pickaxes = {}
	for _, pickData in pairs(self.Pickaxes) do
		Pickaxes[pickData.Name] = pickData
	end
	return Pickaxes
end

function DataStore:GetGems()
	local Gems = {}
	for _, gemData in pairs(self.Gems) do
		Gems[gemData.Name] = gemData
	end
	return Gems
end

return DataStore

Then, within ReplicatedStorage, I have module scripts that will call upon the ObjectDataManager in order to organize and grab the information, for example:

-- Gem Module Script
-- Gather information about all gems in the game
local dataStore = require(game:GetService("ServerScriptService"):WaitForChild("ModuleScripts"):FindFirstChild("ObjectDataManager"))

local Gems = dataStore:GetGems() -- Load in all the gems

return Gems

The gem module script that grabs information for gems works perfectly fine. However, when I try implementing the exact same thing for Pickaxes (same code as the one above except replaced with “GetPickaxes()”, I get an “Infinite yield possible on 'ServerScriptService:WaitForChild(“ModuleScripts”)”.

Here’s the message log:

Infinite yield possible on ‘ServerScriptService:WaitForChild(“ModuleScripts”)’ - Studio
Stack Begin - Studio
Script ‘ReplicatedStorage.ModuleScripts.HitManager’, Line 5

I’ve tried to look for solutions already on here that are similar but I haven’t found any. Any advice or suggestions would be appreciated! Thank you.

This is a rather easy fix, WaitForChild comes with a second argument, which is how long you want to wait for said thing to load, this stops and infinite yield possible errors, as it cant yield forever.

How to use? Just do this anywhere you have WaitForChild()

local Example = Object:WaitForChild('CrazedsWallet',60) -- Waits 60 seconds, if the thing isnt loaded in, it will stop waiting.
1 Like

Technically this fixed the warning from showing up so thank you! Now I just gotta figure out why it can’t find “ModuleScripts”…

1 Like

Are you running this locally? Clients can’t see anything that’s in ServerScriptService.

1 Like

I think the issue I’m running into is that the origin of this script is from a local script within a tool. When the tool is used/activated, I call a module script that ultimately tries to access a script that is inside ServerScriptService, which it cannot do since it was originally called from a local script.

–Thanks for the pointer

I’m glad my idea was correct. That’s exactly what I was thinking. Could you change the solution to the correct one for anyone that finds this post with a similar issue? Since setting a timeout doesn’t actually solve this problem.

2 Likes

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