Hi. I'm trying to make a script that creates parts in random positions around the camera, with those parts moving upwards.
I've succeeded in the first part, but when I try to make the parts move up in a loop, they become slower and slower, and become less smooth in a short period of time.
Here's a video showing the problem. Notice how they start off going upwards smooth and fast, but very quickly lose speed and smoothness.
Here's the code:
local debris = game:GetService("Debris")
local cam = workspace.CurrentCamera
local rand = math.random
local num = 25
while true do
for i = 0, 10 do
local brick = Instance.new("Part")
brick.Anchored = true
brick.CanCollide = false
brick.Size = Vector3.new(1, 1, 1)
brick.Parent = workspace
brick.CFrame = CFrame.new(cam.CFrame.Position + (cam.CFrame:VectorToWorldSpace(Vector3.new(0, 1, 0).unit) + Vector3.new(rand(-num, num), rand(-num, num), rand(-num, num))))
debris:AddItem(brick, 0.75)
local function moveUp()
while true do
brick.CFrame = brick.CFrame * CFrame.new(0, 0.1, 0)
wait()
end
end
spawn(moveUp)
end
wait()
end

2 comments
a loop inside a loop that calls another loop 11 times...
Oh, that makes sense. Is there a way I could reference the ten parts being created in the for loop outside of it?