ViewportFrame spinning objects

Hey folks!

So, I have successfully made a ViewportFrame script for my shop, showing all of the skins you can get, and it is actually pretty decent! :slight_smile:

However, how can I script the Camera in the VPF to ‘Spin’ the character?
(I am aware that you have to spin the character, not the camera :wink:)

Where should I start? Should I tween? Change the CFrame? Any basic pointers?

You can achieve this by rotating the HumanoidRootPart of the characters using CFrame.Angles within a RenderStepped function in the local script.

local viewportFrames = shopFrame:GetChildren() -- Get all ViewportFrames that show characters
for _, frame in ipairs(viewportFrames) do
    if frame:IsA("ViewportFrame") then
        local model = frame:FindFirstChildOfClass("Model") -- Get the Character Model from the VPF
        local humanoidRootPart = model:WaitForChild("HumanoidRootPart")
        while game:GetService("RunService").RenderStepped:Wait() do
            humanoidRootPart.CFrame = humanoidRootPart.CFrame * CFrame.Angles(0, math.pi/200, 0)
        end
    end
end

I basically got all the viewportFrames that are inside your shop frame, all the viewportFrames that have a character inside them. Them I got the character model by searching for a class “Model” in the viewportFrame, then using RenderStepped to rotate the model based on the HumanoidRootPart. You can use this as a reference!

1 Like

Somehow it only works for 1 model. This is probably because of the while loop. The system doesn’t break out of it, and the loop stays forever in the first model.