What are other wait-practices?

I have a massive model; it consists of thousands parts. I constantly need to pivot-rotate it and it takes a few seconds to turn.

local rotation = CFrame.Angles(0, math.rad(0.01), 0)

while true do
	local modelCFrame = P:GetPivot()
	P:PivotTo(modelCFrame * rotation)
	wait(30)
nd

As you can see, I simply put wait(30) to achieve the task, but it is not what I want. I need to call P:PivotTo only after the model has fully turned and loaded… and is seen well on the screen.

I tried this:

task.wait(P:PivotTo(modelCFrame * rotation))

and it still does not work the way I want.
Are there any other wait-methods?

1 Like

Im not really sure about an good solution for this problem but in this case I think ur game lags up to rotate the model, u can use RunService for this

local RS = game:GetService("RunService")
while true do
	local modelCFrame = P:GetPivot()
	P:PivotTo(modelCFrame * rotation)
	RS.RenderStepped:Wait(1) 
end
1 Like

ContentProvider can be a good service for doing that. If your model has meshes, decals, etc. simply put in ContentProvider:PreloadAsync() with the proper provided assets before the loop and it should work.

-- rest of the code
local ContentProvider = game:GetService("ContentProvider")
local assets = {
    -- insert your assets in here
}

ContentProvider:PreloadAsync(assets)

while true do
	local modelCFrame = P:GetPivot()
	P:PivotTo(modelCFrame * rotation)
end

I’m not sure if it can work with regular parts, but you can always find other suitable ways.

1 Like

I don’t believe you’re using task.wait() correctly. task.wait() is a drop-in replacement for wait recommended by Roblox.

It should also be noted that operations like this should use RunService.Heartbeat:Connect(). The physics engine only updates 30 times a second, so there’s little point updating it more than 30 times a second.

1 Like

Not sure what you mean by this, :PivotTo() should be synchronously updating the positions of all the parts within the model, meaning that nothing else should be happening whilst :PivotTo() is still running.

Could you provide a video demonstrating the issue you’re having?

Unless adaptive timestepping is enabled the physics actually update at 240 hz (240 times a second) or 4 times in a frame, a frame happens 60 times a second by default.

Heartbeat runs 60 times a second, after the 4 physics timesteps have completed.

1 Like

In other words, I need to catch event when the model finishes rendering after rotation command started. Something similar is discussed here:

1 Like

The model has no meshes, no decals… simply a few thousands of parts… Most of them have CanCollide, CanTouch and CastShadow as false, to improve fps. It really did! At the moment I think of splitting the whole model into a few models (a few tens, actually) and show only the visible side… I wonder why the engine does not do it.

1 Like