How to tween model rotation

I’ve spent hours the last few days trying to find a method to rotate the whole model in a tween (Bare in mind the model is also in a viewport if that matters). But instead the script only rotates the primary part.

local TweenService = game:GetService("TweenService")
local gamegui = Players.LocalPlayer.PlayerGui:WaitForChild("GameGui")
local finalframe = gamegui.FinalDiceFrame
local dice = finalframe.FinalDiceView.Dice


local face = roll.faces[math.random(1, #roll.faces)]

while dice.PrimaryPart.CFrame.Rotation == face.Rotation do
	face = roll.faces[math.random(1, #roll.faces)]
end

local tweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)

local currentCFrame = dice.PrimaryPart.CFrame
local goalCFrame = currentCFrame * face

local goalModel = { CFrame = goalCFrame }
local tweenModel = TweenService:Create(dice.PrimaryPart, tweenInfo, goalModel)

tweenModel:Play()

--This is the role table stated above the code normally.

roll.faces = {
	CFrame.Angles(0, math.rad(180), 0),                -- Back
	CFrame.Angles(0, math.rad(-90), 0),                -- Left
	CFrame.Angles(0, math.rad(90), 0),                 -- Right
	CFrame.Angles(math.rad(-90), 0, 0),                -- Top
	CFrame.Angles(math.rad(90), 0, 0)                  -- Bottom
}
1 Like

make sure everything is welded to the PrimaryPart and only the PrimaryPart should be anchored

I’ve already tried that, all other parts are unanchored and have cancollide turned off yet only the primary part rotates.

You have to create the tween thing on the actual dice model and not just the PrimaryPart. If that doesn’t work then you can just use :PivotTo() method on the model, CFrame:Lerp() and a loop to animate it.

Welds don’t work in ViewportFrames (I’m assuming that’s the method you’re trying to use here), nor do any other physics. You’ll need to manually update the model using PivotTo every frame to get the effect of a tween.

i totally forgot. Like lemoncat said, welds don’t work inside of viewportframes. you can either lerp or tween them and use :PivotTo()` to move the model or instead of using a regular model use a WorldModel

Thanks for the help, I had no clue physics didn’t apply to viewports as well, I just presumed because it was in the workplace it would work the same.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.