Help with part duplicating script

Hello!
I am quite new to scripting and am struggling with scripting. I want to achieve a part with the size of (4,0.001,4) creating at the position (1022, 0.001, -1022) and then duplicating this part and moving it in the Z axis 4 studs (to the left). I would like to do this in a 10 time sequence.

This is currently what I have:

local Part = Instance.new("Part")
Part.Parent = game.Workspace.CurrentlyPartsSpawned
Part.Size = Vector3.new(4,0.001,4)
Part.Position = Vector3.new(1022, 0.001, -1022)

for count = 10, 10, 1 do 
	script.Parent.Position = Vector3.new(script.Parent.Position.X + 0,script.Parent.Position.Y + 0, script.Parent.Position.Z + 4)
end

This is what is looks like in game:
image

So clearly I was able to make it create 1 part, but it didn’t create anymore to the left. Let me know what you guys think, thank you for your time!

So a few things I noticed are that your for loop does not loop more than once because count = 10 would be the start count, and it would iterate through until your second number there which is also 10. The last number 1 is how much count increases per loop. Since 1 is the default increment setting, you could just remove it. Additionally, you are not creating more parts per iteration because nothing is instancing or duplicating inside the for loop (you can use :Clone for this). With these changes your code would look something like this:

for count = 1, 10 do 
	local ClonedPart = Part:Clone()
	ClonedPart.Position = Vector3.new(Part.Position.X + 0, Part/Position.Y + 0, Part.Position.Z + 4 * count)
	ClonedPart.Parent = game.Workspace.CurrentlyPartsSpawned
end

Note that I don’t know what script.Parent is so I’ve removed it and instead used the first part you instanced for position reference. I have then multiplied by the count to get you one more 4 stud offset per iteration.

1 Like

Thank you so much for breaking that down for me. It’s working perfectly!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.