How to rotate a part with Tweening

Hi, my name is shieldmr3. I’m a scripter and a game developer, I’m the current scripter of an upcoming game called “Geisha” which is a scary game.

I was trying to change the orientation of a part using Tweening, and I’ve used a lot of methods, but none of them worked. Except one, which I used rotation in, and it worked, but when the part moved, the part kept on glitching (rotating on the y and x-axis without on its own). I also tried orientation, which didn’t work (it didn’t give any errors), and tried CFrame too, but it didn’t work, and without errors too. Here’s the script I used:

local OpenValue = script.Parent.Parent.Parent:WaitForChild("Open")
local TweenService = game:GetService("TweenService")

local TweenInformation = TweenInfo.new(
	2,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local TweenPartProps = {
	Position = Vector3.new(-313.643, 4.536, 373.077);
	CFrame = script.Parent.Parent.CFrame * CFrame.Angles(0, 90, 0);
}


local Tween = TweenService:Create(script.Parent.Parent, TweenInformation, {CFrame = script.Parent.Parent.CFrame * CFrame.Angles(0,math.rad(120),0)})


script.Parent.Triggered:Connect(function()
	if OpenValue.Value then
		Tween:Play()
	end
end)

I would really appreciate it if you can help me!

Thanks,

ShieldDevs

2 Likes
  1. You only generated the tween function once, which means it will have a defined CFrame to tween to and that will never change. This means that the object will only do 1 successful rotation and every other one won’t do anything because it will just tween to the orientation it already is.

  2. You are applying the rotation relative to the original orientation of the object you’re trying to rotate. This means that if the object is already tilted, then it will apply the rotation in that tilted axis. You can look up how to do global rotation.

So, I only want it to do 1 rotation only, which rotates it about 90 degrees from its original position. And for the second option that you’ve said, I’ve tried using the same rotation in-game from the server-side, and it worked perfectly fine, but when I try tweening it, it doesn’t work at all, and it doesn’t give any errors too. The part’s rotation/orientation is set to 0,0,0, and I’m trying to rotate it to 0,90,0. I hope I was able to explain my problem a bit more. Thank you for your answer! I would really appreciate it if you can help me!

Can you show me the exact function you used to tween the part?

I used the same script I sent/used in the post above. I can try to explain the script more if you need help understanding it :grinning_face_with_smiling_eyes:

Have you tried running the tween function directly?

I might be late, but to tween a CFrame you need to type ["CFrame"] instead of just CFrame. Maybe that’s one of the reasons.

1 Like