I can't rotate a door model!

  1. What do you want to achieve? Keep it simple and clear!
    -I want to rotate a door 90 degrees. I tried to rotate the primary part of the model to rotate all the model.
  2. What is the issue? Include screenshots / videos if possible!
    -The function ran, but it just didn’t rotate, no error in the output.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    -I don’t know what the **** is the issue, I stuck here for 2 hours. Please help!
    this is the script.
local function test()
	local carPrimaryPart = script.Parent.Parent.Primary
	local TweenService = game:GetService("TweenService")

	local carTweenInfo = TweenInfo.new(
		5,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)

	local newCFrame = carPrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0)

	local carRotationTween = TweenService:create(carPrimaryPart, carTweenInfo, {CFrame = newCFrame})

	carRotationTween:Play()
end

test()
2 Likes

Is the primary part anchored? I think it must be to rotate, and i saw its a car model which is usually unanchored.

Its a door model, i took the script from somewhere else and modified it. The primary part is anchored, or else it will fall off the world and deleted.

2 Likes

Try replacing:

With:

local newCFrame = car:SetPrimaryPartCFrame(car.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(90),0))

This assumes car is your model name.

don’t use function run it
try

local carPrimaryPart = script.Parent.Parent.Primary
local TweenService = game:GetService("TweenService")

	local carTweenInfo = TweenInfo.new(
		5,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)

	local newCFrame = carPrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0)

	local carRotationTween = TweenService:create(carPrimaryPart, carTweenInfo, {CFrame = newCFrame})

carRotationTween:Play()

Happy code!

Oh I found the issue, the script DID WORK, but I set the primaryPart invisible so I didn’t see it. But the new issue is that only the primaryPart rotated, the model didn’t. Can you help me?

your solution did rotate the whole model, but I wanted it to tween

Maybe use CFrame.Lerp then
It allows to smoothly move something without using Tween

The problem is i’m trying to rotate a MODEL, i don’t know how to use lerp on model, can you provide some code?

CFrame:Lerp(model:SetPrimaryPartCFrame(model.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0)))

hopefully im correct

I think you can set the CFRAME of the PrimaryPart so

it could be like this:

PrimaryPart.CFrame = CFrame:Lerp(CFrame.new()*CFrame.Angles(), 0.05)

Well Primary Part Doesnt Rotate a Part. And it will never be this way but you can solve this in two ways.

1.) Loop : Loop through all the Parts and next just play the tween relative to their rotation and position so they tween at the same Form while the model changes its position.

for i,v in Model:GetChildren() do
if v:IsA("BasePart") then
local Tween = game.TweenService:Create(v,
TweenInfo.new(1--[[rest ur stuff)]]),
{["CFrame"] = v.CFrame * CFrame.Angles(0,math.rad(90),0)})

Tween:Play()
end

2.) Physics Based.

Do the Following:

Make Sure that PrimaryPart is Anchored and is Either Near or at the Center of Model AND if it encloses the whole model( second one is not neccesary but it can help you in future if you want to know bounds of your model.). Next Check for any Union or Mesh or Part which has to move in model and add a weld constraint to it.

set Part0 as the PrimaryPart while the Orignal Part to be Part1

Next Make sure that these parts are UNANCHORED.

heres a simple function to do that tedious job for you.

function MakeValidForMovementOrRotation(model)
if not model.PrimaryPart then 
return
else 
for i,v in model:GetChildren() do
if v:IsA("BasePart") and model.PrimaryPart ~= v then
local WC = Instance.new("WeldConstraint",v)
WC.Part0 = model.PrimaryPart 
WC.Part1 = v
v.Anchored = false
elseif v:IsA("UnionOperation") and model.PrimaryPart ~= v then
local WC = Instance.new("WeldConstraint",v)
WC.Part0 = model.PrimaryPart 
WC.Part1 = v
v.Anchored = false
elseif model.PrimaryPart == v then
v.Anchored  = true
end
end
end)

well, it did move the whole model, but It just teleported, it didn’t tween.