Make part rotate depending on how far it's gone

I’m trying to make the handle on this door rotate while the door is moving, kinda like a winder
image
The way I want the handle to rotate


What the door looks like

(still tryna figure out how to make the easing styles line up)

Handles code:

local event = script.Parent.Event

local ts = require(game:GetService('ReplicatedStorage').Modules.LocalTween)
local ti1 = TweenInfo.new(1,Enum.EasingStyle.Exponential,Enum.EasingDirection.In)
local ti2 = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
local ti3 = TweenInfo.new(1,Enum.EasingStyle.Exponential,Enum.EasingDirection.Out)
local weld = script.Parent.Main.Part

local rot = {C0 = weld.C0 * CFrame.Angles(math.rad(360),math.rad(0),math.rad(0))}

event.Event:Connect(function()
	ts:Play(weld,ti1,rot)
	task.wait(1)
	ts:Play(weld,ti2,rot)
	task.wait(1)
	ts:Play(weld,ti2,rot)
	task.wait(1)
	ts:Play(weld,ti3,rot)
end)

Door code:

local event = script.Parent.Event
local handles = script.Parent.Handles.Event

local ts = require(game:GetService('ReplicatedStorage').Modules.LocalTween)
local ti1 = TweenInfo.new(4,Enum.EasingStyle.Sine,Enum.EasingDirection.In)
local ti2 = TweenInfo.new(1,Enum.EasingStyle.Bounce,Enum.EasingDirection.Out)
local door = script.Parent.Door

local openCFrame1 = script.Parent.To1.CFrame
local openCFrame2 = script.Parent.To2.CFrame
local closeCFrame = door.CFrame

--local openS = (Sound when opening, not set yet)
--local closeS = (Sound when closing, not set yet)

local db = false

event.Event:Connect(function()
	if not db then
		ts:Play(door,ti1,{CFrame = openCFrame1})
		task.wait(3)
		ts:Play(door,ti2,{CFrame = openCFrame2})
	end
end)

Currently the handle rotation is controlled by a weld (old ver not WeldConstraint)
Door is setup like:
image

I would do something like distance % studs * 360, where distance is the magnitude between the starting position and wherever the door is now, and studs is the amount of studs it takes to complete a full loop.

1 Like