Function using while true do loop too much

This might be because of wait() throttling. Replace the wait() with task.wait() to avoid this issue.

Now, let’s talk about the while true do loop: the fact of the matter is that you’re starting two while true loops in separate coroutines for every part. This is a little awkward. To your credit, it’s not exactly easy to separate the while true do loop creation from the random move, since each part needs to keep track of its own state. What you need is a cohesive way for your behavior (what’s in the while true do loops) and your state (foward, direction, movecooldown, etc). to interact. What you have now fits that description, but it’s not very elegant. I think it would be more elegant to use object oriented programming here (if you’re not familiar with that, do read the link!).

Consider the following structure:

-- Moving part class; perhaps make a separate modulescript for this that returns MovingPart.
local MovingPart = {}
MovingPart.__index = MovingPart

function MovingPart.new(part)
    local self = {
        Part = part,
        Speed = 10,
        ForwardAllowed = true,
        DirectionAllowed = true,
        DecisionMakingTime = 0.1,
        CanDecide = true,

        _forward = 0,
        _direction = 0,
        _moveCooldown = false,
        - -etc.
    }
    setmetatable(self, MovingPart)

    return self
end

function MovingPart:Decide()
    -- code that sets state
end

function MovingPart:Move()
    -- code that moves the part according to state
end

-- Main script
local movingParts = {}

for _, part in workspace.MovingParts:GetChildren() do
    table.insert(movingParts, MovingPart.new(part))
end

while true do
    for i, movingPart in movingParts do
        if not movingPart then -- In case any get destroyed
            table.remove(movingParts, i)
            continue
        end
        
        if movingPart.CanDecide then
            movingPart:Decide()
        end

        movingPart:Move()

        task.wait()
    end
end

Note that the above is untested and incomplete; it’s just an idea to get you started.