Attempt to index nil with parent line 49

Im trying to clone stages and put them one behind another, but in the 2nd loop im getting the error above.
I am 97.5% sure this part is the problem, but idk why.

for s = 1, #Stages do
			Stages[i].Name = "Stage"..s

Full code here:

local function LoadStages()
	for i = 1, 10 do		
		local Stages = ReplicatedStorage:FindFirstChild("Stages"):GetChildren()
		local stage = math.random(1, #Stages)
	--line 49 under here
ReplicatedStorage:FindFirstChild("Stages"):FindFirstChild("Stage"..stage).Parent = ReplicatedStorage:FindFirstChild("InUse")
		local stageClone = ReplicatedStorage:FindFirstChild("InUse"):FindFirstChild("Stage"..stage):Clone()
		stageClone.Parent = CurrentStages
		stageClone.Primary.Position =, 3.5, 380 + (910 * (i-1)))
		for s = 1, #Stages do
			Stages[i].Name = "Stage"..s

What line is the error coming up? Please send the line.

I said it in the script but sure.

ReplicatedStorage:FindFirstChild("Stages"):FindFirstChild("Stage"..stage).Parent = ReplicatedStorage:FindFirstChild("InUse")

Before line 49, Can you add this print? If it prints nil it appears that the stage doesn’t exist.


You need to use WaitForChild() in line 49:

ReplicatedStorage:WaitForChild("Stages"):WaitForChild("Stage"..stage).Parent = ReplicatedStorage:WaitForChild("InUse")

Yes, it prints nil, so this part must be the problem, since it renumbers all stages frm 1 to #stages

Infinite yield possible. The stage gets named wrong.

Send a screenshot of the Folder in ReplicatedStorage.

Wait you need use WaitForChild() in line 50 too:

local stageClone = ReplicatedStorage:WaitForChild("InUse"):WaitForChild("Stage"..stage):Clone()

I only got 2 stages but it still should work for these 2.
After the first loop the stage, that is left in the Stages folder gets renamed to Stage 2, no matter if i do

for s = 1, #Stages do
	Stages[i].Name = "Stage"..s


for s = 1, #Stages do
	Stages[i].Name = "Stage"..(s-1)

After loop 1:

The model in Stages should get named to “Stage1”, but no matter what, its always “Stage2”

What is #Stages? I can’t see it in your code. Also i think you need to use funtion instead local function.

Which Folder you want to change the name to? Is it the Stages Folder or InUse Folder?

I just noticed:

for s = 1, #Stages do
	Stages[--had to be "s" not "i"].Name = "Stage"..(s-1)

Its not updating the position of “stageClone” correctly, theyre all on the same spot.

Use MoveTo to move the Model.



Are there any errors?

I tried it like this, but how do i get the x and y position of the model?

stageClone:MoveTo( , stageClone:GetPivot(), 380 + (910 * (i-1))))

@mpc19801981 there are no errors.

Try this

stageClone:MoveTo(, 3.5, 380 + (910 * (i-1))))