Tween Rotates in Odd Directions

Hey everyone,

I’ve created a camping stove (its size has been increased to make it easier to see), and its On/Off dial feature constantly tweens incorrectly.

With tweens and CFrames, I understand that tweening moves the centre-most part to the destination. I’ve tried setting the PrimaryPart of the dial as the tab, yet the issue persisted. I looked at this post on the Devforum, yet the solution didn’t work for me.

Ideally, the dial would alternate between a horizontal (Off) and vertical (On) appearance upon click.

Here is my script for critique:

local TweenService = game:GetService("TweenService")

local Stove = script.Parent
local GoldDial = Stove.GoldDial
local DialPrimary = GoldDial.PrimaryPart
local ClickDetector = GoldDial.Clicker.ClickDetector

local DialOriginalCFrame = DialPrimary.CFrame

local On = false

local tweenInfo2 = TweenInfo.new(
	0.25,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In
)

local function DialOpen()
	
	local TweenDialOpen = TweenService:Create(DialPrimary, tweenInfo, {CFrame = DialPrimary.CFrame * CFrame.Angles(math.rad(90), 0, 0)})
	
	TweenDialOpen:Play()
	
	On = true
	
end

local function DialClose()
	
	local TweenDialClose = TweenService:Create(DialPrimary, tweenInfo, {CFrame = DialOriginalCFrame * DialPrimary.CFrame.Rotation})
    -- Tried {CFrame = DialPrimary.CFrame * CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))})

	TweenDialClose:Play()
	
	On = false
	
end

ClickDetector.MouseClick:Connect(function()
	
	if not On then
		
		DialOpen()
		
		print("On")
		
	elseif On then
		
		DialClose()
		
		print("Off")
		
	end
	
end)

Here is the hierarchy order for the dial:
image

The PrimaryPart is the part labelled “Hinge”, which, for reference, is located inside of base of the dial structure.

local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(math.rad(90), 0, 0)

local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)

local tweenInfoIn = TweenInfo.new(
	2,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.In				
	)
local tweenInfoOut = TweenInfo.new(
	2,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.Out			
	)


local tweenOpen = tweenService:Create(hinge, tweenInfoOut, goalOpen)
local tweenClose = tweenService:Create(hinge, tweenInfoIn, goalClose)

I do it slightly differently by using a ProximityPrompt to open and close the doors with the tweenOpen:Play() and tweenClose:Play(), but this is the same basic code in sections. It looks like you are multiplying one CFrame by a different one, when instead you just need to multiply it by the CFrame open and close angles.
Is the Hinge Anchored?

Also, (math.rad(0), math.rad(0), math.rad(0)) is the same thing as (0,0,0)

1 Like

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