Infinite yield possible

i am trying to make a roguelike game with randomly generating rooms and i cant figure this out, the part im using waitforchild for is made and its there but it still does the infinite yield thing. sometimes it works and sometimes it doesn’t. is there a way i can get around this so that it works all the time? i’ve been looking around and i can’t find anything.

can I see your code and is it server or client

this code is called multiple times over and over. theres more code but i don’t think it matters. it is server side

try adding local Door = start:FindFirstChild(“Door”) or start:WaitForChild(“Door”)
before the NewPostion and replace start:WaitForChild("Door) in your Newposition variable with Door

it still happens, i think its something with the :WaitForFirstChild() part. it just doesn’t think the part exists even though it does, and the part is named right because it is cloned multiple times but it still does it sometimes.

i was wondering if there was an alternative way to do :WaitForFirstChild() without using :WaitForFirstChild()

try this

function waitforchildv2(Parent: Folder,ChildName: Folder, Timeout: number)
   if Timeout == 0 then return end
   if Parent:FindFirstChild(ChildName) then
   	return Parent:FindFirstChild(ChildName)
   else
   	task.wait()
   	waitforchildv2(Parent, ChildName, Timeout-1)
   	return
   end
end

example

print(waitforchildv2(workspace, "cheeseburger", 5).Name)

it’s easy to make a function with the same feature as :WaitForChild() .

local UNNORMAL_FIND_TIME = 100
local function NONRBX_WaitForChild(parent: Instance, childName: string, timeOut: number?)

	local child = nil
	local found = false
	local count = 0

	while not found do
		count += 1
		if timeOut ~= nil then
			if count > timeOut then
				break
			end
		end
		if count > UNNORMAL_FIND_TIME then
			warn(string.format("Infinite yield possible on %s:WaitForChild(%s)", tostring(parent), childName))
			return nil
		end
		child = parent:FindFirstChild(childName) 
		found = child ~= nil
		if found then
			break
		else
			task.wait(0.05)
		end

	end 
	return child
end	

When make it a loop
NONRBX_WaitForChild(script, "MODEL")

use it

print(NONRBX_WaitForChild(script, "MODEL"))

edit: Update Loop Handling Logic

now it still doesn’t work, it does the same thing. idk why it does this.

local Door = start:WaitForChild("Door",30)

local NewPosition = Door.CFrame + Vector3.New(-50.5, 0, 0) 

This issue should maybe arise with runtime adding instances through Script

The issue is that Roblox Studio “thinks” the instance “Door” located in start instance will never add. And as always, the issue always lies somewhere else..
Can you share the script what that “start” instance is, how it is created and when?

Between Scripts are asynchronous but in your case it is only possible that Door is not added correctly

Just to test - can you please go to the properties of workspace and turn off StreamingEnabled?

If the issue still occurs, then it means that the part just doesn’t exist, in which case we’ll need to see the ‘directory’ a bit more.

If the issue no longer occurs, then it means that the part is not being loaded in (due to it not being close enough to the player, for example). If you do need it to be loaded in constantly, consider changing the streaming mode of the model (ModelStreamingMode) to Persistant. (Turn streaming enabled back on to change the setting)

the script is in the workspace and just creates copies of the entire rooms and moves them based on the last rooms door position, and it does this many times over and over. sometimes it works fine but sometimes it screws up and thinks that the door in the room just doesn’t exist even though it does. or maybe it doesn’t think the part is named right even though all the door parts are named the same thing.