How can I fix this infinite yield if everything I did was true?

Hello! So, I have a script that supposed to find the “Maps” Folder In replicated storage

local ServerStorage = game:GetService("ServerStorage")

local MapsFolder = ServerStorage:WaitForChild("Maps")

But for some reason when I Have a Maps Folder Inside ReplicatedStorage With all of the maps, It said this,

  14:21:16.085  Infinite yield possible on 'ServerStorage:WaitForChild("Maps")'  -  Studio
  14:21:16.086  Stack Begin  -  Studio
  14:21:16.086  Script 'ServerScriptService.GameHandler', Line 7  -  Studio - GameHandler:7
  14:21:16.087  Stack End  -  Studio

Its really strange and Im looking for help on how to fix this, it seems like a glitch considering the fact that the “Maps” Folder Exist and that their are grouped models in their.

Hi!

You defined the ServerStorage service here. You can just change it to ReplicatedStorage.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MapsFolder = ReplicatedStorage:WaitForChild("Maps")
2 Likes

Add a time next to waitforchild

:WaitForChild("..." ,5)

Infinite yield mean your WaitForChild will infinity wait when he not find the object. If you add a time, it will render nil so there will be no warn and you can replay the code if needed.

If all your folders are named “Map” it can be a problem, because the script can’t know what is the good one, what of them it need to get.

I have a script that supposed to find the “Maps” Folder In replicated storage
Your code actually search in the server storage and not the replicated storage.