Help Tweening a Model's Orientation

Thank you for taking the time to read my post.

  1. What do I want to achieve?
    Something simple. I want to achieve rotating a model 45 degrees on its Y-Axis to simulate opening a door through a proximityPrompt connected to a Tween.

  2. What is the issue?
    So far throughout all of the iterations I have provided, nothing has worked.

Here was my original idea: I will include everything in the script once, since its just a few variables, but in future iterations, I will only include what is inside my “goal” table, as I feel it is most relevant.

local TweenService = game:GetService("TweenService")
local prompt = script.Parent
local model = script.Parent.Parent.Parent
local door = model.PrimaryPart

local goal = {
	CFrame = CFrame.Angles(0, math.rad(-45), 0),
}

-- Create the Tweens to Open and Close the Door
local openTween = TweenService:Create(door, TweenInfo.new(2), goal)

prompt.Triggered:Connect(function()
	print("Tween Play Now")
	openTween:Play()
end)

“model” is the door itself, and “door” is the PrimaryPart I am trying to use to rotate the model.
In the above iteration, the only thing in the model that rotates is the primaryPart, not anything else.

Here was my next iteration, attempting to use PivotTo and GetPivot to move the models.

local goal = {
	Pivot = model:PivotTo(model:GetPivot() * CFrame.Angles(0, math.rad(-45), 0))
}

-- Create the Tweens to Open and Close the Door
local openTween = TweenService:Create(model, TweenInfo.new(2), goal)

This succeeded in properly orienting the model, except without the use of the Tween. The code inside the table executes without calling the tween whatsoever.

  1. What solutions have I tried thus far?

Honestly, a lot of documentation research about TweenService and Models. In addition to some YouTube videos and DevForum posts. Most of the tutorial videos and old posts I looked at used deprecated methods like :SetPrimaryPartCFrame in order to move models.

I also saw a potential solution being to un-anchor everything except the primaryPart in the door model, and weld all other parts to that, while using the first method. However, I would really like to avoid that if possible, as there are a lot of other parts in the door.

Any help is appreciated, thanks in advance.

2 Likes

Keep the primary part anchored but unanchor every other part of the door. Then set up welds that weld all the unanchored parts to the primary part. This way when you tween the primary part, all the other parts of the door move with it.

1 Like

Pretty sure you need to multiply the CFrame by CFrame.Angles in the first script.

local goal = {
    CFrame = door.CFrame * CFrame.Angles(0, math.rad(-45), 0)
}

I tried that too, same result as the first example.

Thank you for the suggestion. No offense, but if you had finished the post, you would have seen that I did see this solution, and would like to find an alternative method, although if it is the only possible remedy, I will do it.

Have you welded everything to the PrimaryPart with only the PrimaryPart being anchored?
This is pretty much the only way to move entire models.

Set up a script then that loops through all the other parts and welds it to the primary part when the game starts. I missed the part at the end of the post, however I fully recommend this solution vs any other hacky solution.

As I have now stated twice, I would like to avoid that method if at all possible. What I would really like to get to the bottom of is why, when using the Pivot method, the code inside my table runs before the Tween is even called in the first place.

You are most likely correct in this assessment. Do you have any idea that, when using the Pivot method, the code inside my table runs before the tween is called? That is really what I would like to find out.

:PivotTo is a function. The reason it runs is because when the table is created, it runs the function in order to detemine what the Pivot key should be equal to within the table. This is completely the wrong way to use this function, as it has nothing to do with tweens. :PivotTo does not return anything either. It just moves the model when it is called.

Edit: Clarification

1 Like

You can’t manipulate the Pivot property directly with scripts, only with :GetPivot and :PivotTo which is why the only easy way to move a model is by welding everything to the PrimaryPart.

1 Like

Thank you both for the explanation. It would seem I have to go with the un-anchoring method.

1 Like

I just tested the first script with a Model and it works. All you have to do is welding and then it should work.

local TweenService = game:GetService("TweenService")
local prompt = script.Parent
local model = script.Parent.Parent.Parent
local door = model.PrimaryPart

local goal = {
	CFrame = door.CFrame * CFrame.Angles(0, math.rad(-45), 0),
}

-- Create the Tweens to Open and Close the Door
local openTween = TweenService:Create(door, TweenInfo.new(2), goal)

prompt.Triggered:Connect(function()
	print("Tween Play Now")
	openTween:Play()
end)

Here is my suggestion for welding the parts via script:

local TweenService = game:GetService("TweenService")
local prompt = script.Parent
local model : Model = script.Parent.Parent.Parent
local door = model.PrimaryPart

local goal = {
	CFrame = CFrame.Angles(0, math.rad(-45), 0),
}

-- Create the Tweens to Open and Close the Door
local openTween = TweenService:Create(door, TweenInfo.new(2), goal)

-- Weld code
for i, child : Part in ipairs(model:GetDescendants()) do
	if child:IsA("BasePart") and child ~= door then
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = child
		weld.Part1 = door
		child.Anchored = false
	end
end


prompt.Triggered:Connect(function()
	print("Tween Play Now")
	openTween:Play()
end)

The weld code does not work unfortunately. I tried ungrouping any other models I had inside of “door1” and checked names. When I look inside the model itself, there are no new instances created, and nothing is anchored.

Oh woops, let me correct it, I forgot the parent the weld to the individual parts

local TweenService = game:GetService("TweenService")
local prompt = script.Parent
local model : Model = script.Parent.Parent.Parent
local door = model.PrimaryPart

local goal = {
	CFrame = CFrame.Angles(0, math.rad(-45), 0),
}

-- Create the Tweens to Open and Close the Door
local openTween = TweenService:Create(door, TweenInfo.new(2), goal)

-- Weld code
for i, child : Part in ipairs(model:GetDescendants()) do
	if child:IsA("BasePart") and child ~= door then
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = child
		weld.Part1 = door
        weld.Parent = child --forgot to parent the weld to the part
		child.Anchored = false
	end
end


prompt.Triggered:Connect(function()
	print("Tween Play Now")
	openTween:Play()
end)

I really appreciate it, thanks for the help.

1 Like

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