So I’m trying to make a sliding door. Everything is working fine, except when I enable the script, it rotates the part whilst tweening it to the position given. How can I stop the Model from orientating when tweening it?
Here is my current script:
local TweenService = game:GetService("TweenService")
local Model = script.Parent.MainPart
local tweenInfo = TweenInfo.new(
5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false
)
TweenService:Create(Model, tweenInfo, {CFrame = CFrame.new(53.996, 40.478, -33.288)}):Play()
script.Disabled = true
1 Like
local tween = TweenService:Create(Model, tweenInfo, {CFrame = CFrame.new(53.996, 40.478, -33.288)})
tween:Play()
task.wait(1)
tween:Stop()
Also, why are you disabling the script?
I hope that works. Do note, I am tweening a model, which I have a primary part set, which is the window, and the rest is welded to that primary part.
I’m disabling the script because the door opens when you click a button. So when someone wants to go through the door, which leads to a staff room, they click a button, which enables the script to play the tween.
Instead of disabling the script, can’t you use a BindableEvent to tell it when to start the tween?
I prefer to use the disable. I use that for all my tween scripts, and works perfectly fine. The only issue I’m having currently is the tween rotating the part, whilst also moving it to the position. I need it to just tween to the position, I don’t need it changing the orientation.
You can try :PivotTo
I think this should work
local model = -- Path to model
local t = 0.1
local startCFrame = model.PrimaryPart.CFrame
local endCFrame = CFrame.new()
for i = 0, 1, t do
local goal = startCFrame.Position:Lerp(endCFrame.Position,i) * startCFrame.Rotation
model:PivotTo(goal)
task.wait()
end
Edit : I forgot to put task.wait()
Where do I put what position I want it to tween to? I see at the end you’ve put startCFrame.Rotation, I don’t want it to rotate.
The endCFrame will be the position it will tween to. If you want it to be a Vector3
, then try this
local model = -- Path to model
local t = 0.1
local startCFrame = model.PrimaryPart.CFrame
local endPos = Vector3.new()
for i = 0, 1, t do
local goal = startCFrame.Position:Lerp(endPos,i)
model:PivotTo(CFrame.new(goal)) -- When you create a new CFrame, it will automatically have no rotation.
task.wait()
end
I added * startCFrame.Rotation
so that it will always maintain the rotation it started as.
Okay, thanks. Let me see if it works.
Okay it worked, although it didn’t tween…
Edit: It still rotated the part.
It is not supposed to tween? It just uses the :Lerp()
function, if you want it to be smoother then set the t
variable to something smaller.
My original scripted tweened. I need the part to tween, I just need the orientation fixed in my original script.
If it rotated the part, then that means it already had a rotation set. Just multiply goal by startCFrame.Rotation
Ok, well in the end goal of your tween, just use CFrame.new(x,y,z)
then it will have a rotation of Vector3.new(0,0,0)
Where do I put that in my original script?
local TweenService = game:GetService("TweenService")
local Model = script.Parent.MainPart
local tweenInfo = TweenInfo.new(
5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false
)
local goal = {CFrame = CFrame.new(53.996, 40.478, -33.288) * Model.PrimaryPart.CFrame.Rotation}
-- Multiply it by the CFrame.Rotation so that both start and goal CFrames will have the same CFrame.Rotation
TweenService:Create(Model, tweenInfo, goal):Play()
script.Disabled = true
6 Likes
This is what I’m getting in my output when I enable the script.
Copy paste the code again, I editted it because I accidentally multiplied a table by a CFrame