Having trouble with Infinite Yield bug

Hi, I am trying to make a game similar to Tower of Hell, and I am having trouble scripting the script that generates the stages in the tower. When I run the script it says in the output “Infinite yield possible on 'Workspace.Storage.End:WaitForChild(“Center”)”.
Here is the script:

local Stages = StagesFolder:GetChildren()
local Tower = game.Workspace:WaitForChild("Tower")
local End = Storage:WaitForChild("End")

local Floor1
local Floor2
local Floor3
local Floor4
local Floor5
local Floor6

debounce = false

function NewTower()
	debounce = true
	Floor1 = Stages[math.random(1, #Stages)]:Clone()
	Floor1.Parent = Tower
	Floor1.PrimaryPart = Floor1:FindFirstChild("Center")
	Floor1:SetPrimaryPartCFrame(Floor1.Center.CFrame)
	local Floor1Height = Floor1.Height.Value
	wait()
	Floor2 = Stages[math.random(1, #Stages)]:Clone()
	Floor2.Parent = Tower
	Floor2.PrimaryPart = Floor2:FindFirstChild("Center")
	Floor2:SetPrimaryPartCFrame(Floor1.Center.CFrame + Vector3.new(0, Floor1Height, 0))
	Floor2:SetPrimaryPartCFrame(Floor2.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor2Height = Floor2.Height.Value
	wait()
	Floor3 = Stages[math.random(1, #Stages)]:Clone()
	Floor3.Parent = Tower
	Floor3.PrimaryPart = Floor3:FindFirstChild("Center")
	Floor3:SetPrimaryPartCFrame(Floor2.Center.CFrame + Vector3.new(0, Floor2Height, 0))
	Floor3:SetPrimaryPartCFrame(Floor3.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor3Height = Floor3.Height.Value
	wait()
	Floor4 = Stages[math.random(1, #Stages)]:Clone()
	Floor4.Parent = Tower
	Floor4.PrimaryPart = Floor4:FindFirstChild("Center")
	Floor4:SetPrimaryPartCFrame(Floor3.Center.CFrame + Vector3.new(0, Floor3Height, 0))
	Floor4:SetPrimaryPartCFrame(Floor4.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor4Height = Floor4.Height.Value
	wait()
	Floor5 = Stages[math.random(1, #Stages)]:Clone()
	Floor5.Parent = Tower
	Floor5.PrimaryPart = Floor5:FindFirstChild("Center")
	Floor5:SetPrimaryPartCFrame(Floor4.Center.CFrame + Vector3.new(0, Floor4Height, 0))
	Floor5:SetPrimaryPartCFrame(Floor5.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor5Height = Floor5.Height.Value
	wait()
	Floor6 = Stages[math.random(1, #Stages)]:Clone()
	Floor6.Parent = Tower
	Floor6.PrimaryPart = Floor6:FindFirstChild("Center")
	Floor6:SetPrimaryPartCFrame(Floor5.Center.CFrame + Vector3.new(0, Floor5Height, 0))
	Floor6:SetPrimaryPartCFrame(Floor6.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor6Height = Floor6.Height.Value
	wait()
	End.PrimaryPart = End:WaitForChild("Center")
	End:SetPrimaryPartCFrame(Floor6.Center.CFrame + Vector3.new(0, Floor6Height), 0)
	End:SetPrimaryPartCFrame(End.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	debounce = false
end

Any help will be greatly appreciated!
Thank You!

There’s nothing inside the End variable named “Center”, are you sure that’s what you’re trying to search for?

Yes, I’m trying to search for the part named “Center” inside the End Model.
And sorry I forgot to add this variable of the script in my post: local Storage = game.Workspace:WaitForChild(“Storage”)

Here is what the script is supposed to look like with the missing variable

local Stages = StagesFolder:GetChildren()
local Storage = game.Workspace:WaitForChild(“Storage”)
local Tower = game.Workspace:WaitForChild("Tower")
local End = Storage:WaitForChild("End")

local Floor1
local Floor2
local Floor3
local Floor4
local Floor5
local Floor6

debounce = false

function NewTower()
	debounce = true
	Floor1 = Stages[math.random(1, #Stages)]:Clone()
	Floor1.Parent = Tower
	Floor1.PrimaryPart = Floor1:FindFirstChild("Center")
	Floor1:SetPrimaryPartCFrame(Floor1.Center.CFrame)
	local Floor1Height = Floor1.Height.Value
	wait()
	Floor2 = Stages[math.random(1, #Stages)]:Clone()
	Floor2.Parent = Tower
	Floor2.PrimaryPart = Floor2:FindFirstChild("Center")
	Floor2:SetPrimaryPartCFrame(Floor1.Center.CFrame + Vector3.new(0, Floor1Height, 0))
	Floor2:SetPrimaryPartCFrame(Floor2.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor2Height = Floor2.Height.Value
	wait()
	Floor3 = Stages[math.random(1, #Stages)]:Clone()
	Floor3.Parent = Tower
	Floor3.PrimaryPart = Floor3:FindFirstChild("Center")
	Floor3:SetPrimaryPartCFrame(Floor2.Center.CFrame + Vector3.new(0, Floor2Height, 0))
	Floor3:SetPrimaryPartCFrame(Floor3.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor3Height = Floor3.Height.Value
	wait()
	Floor4 = Stages[math.random(1, #Stages)]:Clone()
	Floor4.Parent = Tower
	Floor4.PrimaryPart = Floor4:FindFirstChild("Center")
	Floor4:SetPrimaryPartCFrame(Floor3.Center.CFrame + Vector3.new(0, Floor3Height, 0))
	Floor4:SetPrimaryPartCFrame(Floor4.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor4Height = Floor4.Height.Value
	wait()
	Floor5 = Stages[math.random(1, #Stages)]:Clone()
	Floor5.Parent = Tower
	Floor5.PrimaryPart = Floor5:FindFirstChild("Center")
	Floor5:SetPrimaryPartCFrame(Floor4.Center.CFrame + Vector3.new(0, Floor4Height, 0))
	Floor5:SetPrimaryPartCFrame(Floor5.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor5Height = Floor5.Height.Value
	wait()
	Floor6 = Stages[math.random(1, #Stages)]:Clone()
	Floor6.Parent = Tower
	Floor6.PrimaryPart = Floor6:FindFirstChild("Center")
	Floor6:SetPrimaryPartCFrame(Floor5.Center.CFrame + Vector3.new(0, Floor5Height, 0))
	Floor6:SetPrimaryPartCFrame(Floor6.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	local Floor6Height = Floor6.Height.Value
	wait()
	End.PrimaryPart = End:WaitForChild("Center")
	End:SetPrimaryPartCFrame(Floor6.Center.CFrame + Vector3.new(0, Floor6Height), 0)
	End:SetPrimaryPartCFrame(End.Center.CFrame * CFrame.Angles(0, math.rad(180), 0))
	debounce = false
end

Possibly you don’t have the center part inside the end model, although it would be easier to identify any plausible solutions if I could see the game explorer tab. It is more likely an issue from the location of the models/parts then a scripting error.

The center part is in the end model. It it saying the infinite yield issue is on the End.PrimaryPart = End:WaitForChild(“Center”) line

Again, I would have to see the game explorer tab, the problem doesn’t seem to be with the code. Generally an infinite yield error arises from a missing instance. But if you just simply want to avoid this error from showing completely you could do End.PrimaryPart = End:WaitForChild(“Center”, 5) and it would timeout after 5 seconds if it doesn’t find the instance instead of returning an error.

1 Like

Is center an instance from a script?

Also, may you please show me the explorer?

1 Like

Here is the explorer tab
image
And here is also the output message
image

Well does it work properly in-game besides the error message displaying? If so I would try using End.PrimaryPart = End:WaitForChild(“Center”, 7) basically just adding , 7 which is the wait time in seconds until it breaks the line of code. Possibly because there is a slow run time on the script. But if you try it let me know if it works for you.

So I tried it in game and it still seems to have the same problem, so I tried End.PrimaryPart = End:WaitForChild(“Center”, 7) and this is what came out in the output

Well it’s relatively hard for me to identify an error from the screenshots you have provided, it would be easier for me to edit from the game itself. Unless of course you do not wish to do that then it’s completely fine, otherwise I would be more than willing to help.

I am fine with you editing it from the game itself. How would I let you do that?

You would enable team create and then search my user from there and give me editing permission. If you are aware on the process of doing that.

Yes, I am aware of the process of doing that, but it seems that I am unable to give you editing permissions. It wont let me click allow you to edit. I’m not sure if you maybe have to be friends or what.

I believe so, I have sent you a friend request.

Ok, you now have editing permission.

1 Like

Alright I saw the errors, you just needed to switch your default body type to r6 and anchor the “Center” part.

1 Like

Ok! Thank you so much for the help!

1 Like