Cloning part in `for` loop crashes studio

I’m trying to clone a part in a for loop, but it crashes studio for some odd reason.
It remains stable if I create a new instance of a part or if I don’t set the cloned part to be anchored.

The part that I am cloning is not anchored.

for i = 1, 2, 1 do
	local corner = part:Clone()

	corner.Anchored = true
	corner.Parent = workspace
end
1 Like

I tried copying your code into my studio and it worked with no issues
therefore the error is caused by the specific part you’re cloning. can you give more details about that part?

1 Like

It’s a 4, 4, 4 cube with anchored set to false.

1 Like

image

it still works as expected, maybe try deleting the part you’re trying to clone and make a new one with the same properties?

1 Like

are you calling the for loop in a fast while loop or runservice event? if so it will clone it alot and studio will crash

1 Like

Still doesn’t work.
This is what happens when I run the script.

1 Like

I am not running it in another loop

1 Like

alright now i know what the issue is

try placing the script somewhere else just don’t place it inside of the part because you’re cloning the script too, which runs another loop and so on

use task.wait() within the for loop.

We need more context to help you out… the script you provided should work as expected

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