Attempt to index nil with parent line 49

Hello,
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
		end

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 = Vector3.new(733.5, 3.5, 380 + (910 * (i-1)))
		UpdateColors(stageClone)
		
		for s = 1, #Stages do
			Stages[i].Name = "Stage"..s
		end
	end
end

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.

print(ReplicatedStorage:FindFirstChild("Stages"):FindFirstChild("Stage"..stage))

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()

Capture
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
end

or

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

After loop 1:
Capture

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)
end

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

Use MoveTo to move the Model.

Example

Model:MoveTo(Vector3.new(0,0,0))

Are there any errors?

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

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

@mpc19801981 there are no errors.

Try this

stageClone:MoveTo(Vector3.new(733.5, 3.5, 380 + (910 * (i-1))))