How to fix "script.Parent:Clone()" resulting in "startScript re-entrancy has exceeded 3"

Recently, I have noticed a few people struggling with the error,


startScript re-entrancy has exceeded 3

So for those of you that don’t know how to fix this, let me explain.
So when you write out something like,


script.Parent:Clone().Parent = workspace

You will get the error because you are cloning the script inside the part which will cause issues.
Here’s a simple script that will resolve this,


local parttoclone = script.Parent
local newpart = parttoclone:Clone()

for _, v in ipairs (newpart:GetChildren() --[[Must have get children at the end or it will error.]]) do
	if v:IsA("Script") then
		v:Destroy()
	end
end
emphasized text

I hope this resolves this issue for anyone that has it.

4 Likes