Randomly Revolving Cube

This might not be necessary if that model works, but here it is anyway.

local RunService = game:GetService("RunService")

local rotationDegPerSec = 5
local minWaitBetweenDirChange = 4
local maxWaitBetweenDirChange = 10

local partToRotate = -- the part you want to rotate

local rotationRadPerSec = math.rad(rotationDegPerSec)
local rotating = true

local attach0, attach1 = Instance.new("Attachment"), Instance.new("Attachment")
attach0.Parent, attach1.Parent = partToRotate, workspace.Terrain

local alignOri = 
Instance.new("AlignOrientation")
alignOri.RigidityEnabled = true
alignOri.Attachment0, alignOri.Attachment1 = attach0, attach1
alignOri.Parent = partToRotate

local alignPos = 
Instance.new("AlignPosition")
alignPos.RigidityEnabled = true
alignPos.Attachment0, alignPos.Attachment1 = attach0, attach1
alignPos.Parent = partToRotate

local nextDirChangeTick, rotVelocity

local function getRandNum()
    return math.random()*(-1)^math.random(1, 2)
end

local function changeTickAndDir()
    nextDirChangeTick = tick()+math.random(minWaitBetweenDirChange, maxWaitBetweenDirChange)
    local direction = Vector3.new(getRandNum(), getRandNum(), getRandNum()).Unit
    rotVelocity = direction*rotationRadPerSec
end


changeTickAndDir()

partToRotate.Anchored = false
attach1.CFrame = partToRotate.CFrame

local _, delta = nil, 0

while rotating do
    if tick() >= nextDirChangeTick then
        changeTickAndDir()
    end
    local rotChange = rotVelocity*delta
    attach1.CFrame *= CFrame.Angles(rotChange.X, rotChange.Y, rotChange.Z)
    _, delta = RunService.Stepped:Wait()
end
8 Likes