Infinite yield possible on 'ServerStorage:WaitForChild("Scripts")'

Hello, developers. Recently, I was introduced to this error. The code was working, until I tested it again and it suddenly stopped working and was erroring with attempting to call :FindFirstChild() on nil. So I replaced all the FindFirstChilds with WaitForChilds thinking it would work, but it didn’t. Here is the code.

local DOORMS = {}

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Scripts = ServerStorage:WaitForChild("Scripts")

local ROBLOXMS = require(ReplicatedStorage:WaitForChild("ROBLOXMS"))

local ProximityHandler = Scripts:WaitForChild("ProximityHandler")

local Tunes = {
	["Metal Door"] = {
		Distance = 10,
		Key = Enum.KeyCode.E,
		GamepadKey = Enum.KeyCode.ButtonX,
		RequireSight = true,
		Name = "metal door"
	},
}

function DOORMS.Init(DoorMain: Script, TuneName)
	local Tunes = Tunes[TuneName]
	
	local DoorSensor = DoorMain:FindFirstChild("DoorSensor")
	local Door = DoorMain:FindFirstChild("SeperateDoor")

	local MainSensor = DoorSensor:FindFirstChild("Main")

	local ProximityPrompt = DOORMS.CreateDoorProximity(Tunes.Distance, Tunes.Key, Tunes.GamepadKey, Tunes.RequireSight)
	ProximityPrompt.Parent = MainSensor
	
	local ClonedProximityHandler = ProximityHandler:Clone()
	ClonedProximityHandler.Parent = ProximityPrompt
	ClonedProximityHandler.Enabled = true
end

function DOORMS.Shown(DoorSensor: Model) -- Client
	local Neons = {
		Neon1 = DoorSensor:FindFirstChild("Neon1"),
		Neon2 = DoorSensor:FindFirstChild("Neon2"),
		Neon3 = DoorSensor:FindFirstChild("Neon3")
	}
	
	for _,v in pairs(Neons) do
		ROBLOXMS.TweenColor(Neons, Color3.fromRGB(0, 255, 0), 1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	end
end

function DOORMS.Hidden(DoorSensor: Model) -- Client
	local Neons = {
		Neon1 = DoorSensor:FindFirstChild("Neon1"),
		Neon2 = DoorSensor:FindFirstChild("Neon2"),
		Neon3 = DoorSensor:FindFirstChild("Neon3")
	}

	for _,v in pairs(Neons) do
		ROBLOXMS.TweenColor(Neons, Color3.fromRGB(255, 0, 0), 1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	end
end

function DOORMS.Interact() -- ???
	
end

function DOORMS.CreateDoorProximity(Distance: number, Key: Enum.KeyCode, GamepadKey: Enum.KeyCode, RequireSight: boolean): ProximityPrompt
	local ProximityPrompt = Instance.new("ProximityPrompt")
	ProximityPrompt.MaxActivationDistance = Distance
	ProximityPrompt.KeyboardKeyCode = Key
	ProximityPrompt.GamepadKeyCode = GamepadKey
	ProximityPrompt.RequiresLineOfSight = RequireSight
	ProximityPrompt.Style = Enum.ProximityPromptStyle.Custom

	return ProximityPrompt
end

return DOORMS

This is where everything is located.
Screenshot 2023-12-16 165908
DOORMS is located in ReplicatedStorage.

3 Likes

If this is in a LocalScript, ServerStorage does not exist on the client, even if you call :GetService(). You’ll have to switch it over to a server script, hence the service name “ServerStorage”. Move the needed instances to ReplicatedStorage if you need the client to be able to access them.

3 Likes

since DOORMS is a modulescript, it will inherit the type of the script that tried to retrieve the modulescript (serverscript/localscript). like @Wizzthepixelcat said, if you use a localscript, serverstorage does not exist cannot be viewed by the localscript and will be shown as empty. only serverside scripts can see instances inside ServerStorage and ServerScriptService.

1 Like

It gets called by a server script first to init it. Anything that is commented ‘client’ is called by the client. You can assume anything else is called by a script.

The client calls it after init takes place, but the init isn’t taking place because of this.

1 Like

i’m not fully sure what you are trying to say, but you definitely cant access the module from a localscript since it’s in serverstorage. anyway the solution is moving the scripts folder to like replicatedstorage or any other service that clients can see

1 Like

It’s duplicating the localscript and enabling it in workspace. The code still works because its a script set to Client under the RunContext.

The problem has nothing to do with the localscript. It isn’t even being ran because it’s erroring before its existence in workspace.

anyway can you just send me the game file so i can solve things quickly

I can send you code, but not the game.

Here is the code for the script that is calling the init (which is the only function being called.)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DOORMS = require(ReplicatedStorage:WaitForChild("DOORMS"))

DOORMS.Init(script, "Metal Door")

is that the one that has RunContext set as client?

No. That script is never being ran like I said because of this error.
This is just a regular script in workspace, nothing fancy to it.

Do you have 2 or more Folders named Scripts?

can you put like print(game:GetService("ServerStorage"):GetChildren()) in the DOORMS module so i can know if it can read the insides

even if there were 2 folders it wouldn’t throw a infinite yield error lol

Yes I did this before, I should have told you the results in the beginning.
It’s 0 children.
I’ll do some more testing, but nothing else is calling it. I think I might know why now, so I’ll get back to you after I test this thought.

i know you have mentioned that the problem got nothing to do with a localscript, but that’s a behavior of a clientsided script. anyway goodluck finding the problem here.

1 Like

I’ve figured it out. The localscript is calling the module AFTER the script is done with the init function. I’m going to put all the server stuff in the server functions.

Thanks for the help!

1 Like

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