Hey everyone!

I want to make a 10 by 10 grid of boxes and make them move up and down with the sin() of elapsedTime(), but I'm bumping into some performance issues.

Here's the essencial part of the LocalScript, placed in ReplicatedFirst:


local function UpdateCratePosition(crateIndex, dTime)
    if crateIndex ~= nil then
        local sin = math.sin(elapsedTime()+(crateIndex * 0.1)) * 0.1 * dTime
        local cos = math.cos(elapsedTime()+(crateIndex * 0.1)) * 0.1 * dTime
        boxList["boxes"][crateIndex].CFrame = boxList["boxes"][crateIndex].CFrame * CFrame.new(0, sin , cos)
    end
end
 

local function onRenderStep(deltaTime)
	for i = 1, #boxList["boxes"] do
	UpdateCratePosition(i, deltaTime)
    end
end
 
RunService.RenderStepped:Connect(onRenderStep)

Is there a better way of moving all these boxes? Should I use coroutines? or tweening?

It runs smooth on my pc as is, but on ipad and mobile it stutters.

(I'm basically looking for the Unity equivalent of Update() and time.DeltaTime)