Why does this slow down over time?

heres the main script that running this:

local folder = Instance.new("Folder")
folder.Parent = script.Parent
while wait(.75) do
	local part = Instance.new("Part")
	part.Size = script.Parent.Size
	part.Position = script.Parent.Position
	part.Parent = script.Parent.Folder
	part.Anchored=true
	part.Material = Enum.Material.ForceField
	part.Color = script.Parent.Color
	part.CanCollide = false
	part.CastShadow = false

	local clone = script.Parent.moving:Clone()
	clone.Parent = part
	clone.Enabled = true
end

here’s the script that is in charge of moving the parts:

for i= 1, 45 do
	local num = i^1.05/50
	local num2 = i^1.1/65
	if num2 >= 1 then
		num2 = 1
	end
	script.Parent.Transparency = num2
	script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,num,0)
wait()
end
script.Parent:Destroy()
1 Like

Try task.wait instead of wait in both scripts, to start.

A better solution is to use TweenService—you can just create a tween right after you make the part in the main script and play it, no need for a separate script for each part or anything.

1 Like

To answer your original question in the title, it’s because the script is cloning another script an indefinite number of times causing a temporary memory leak.

Additionally, you are parenting the part before setting all the properties, which is a bad practice and slows your game down.