How to make a math function multiply a varying value till it reaches a certain value

As the title says, I need help with making a way that that multiples a CFrame value that can vary till it reaches a value I specify in the script below.

local DOOR_TWEEN_SERVICE = {}

function DOOR_TWEEN_SERVICE:TWEEN_DOOR(Door)
	local TweenService = game:GetService("TweenService")
	local TweenInfo = TweenInfo.new(1.25, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
	local GOALS = {
		FIRST_GOAL = {CFrame = CFrame.new(Door.Position) * CFrame.Angles(0, math.rad(-90), 0)},
		SECOND_GOAL = {CFrame = CFrame.new(Door.Position) * CFrame.Angles(0, math.rad(-180), 0)}
}
	local OPEN_STATUS = TweenService:Create(Door, TweenInfo, GOALS.FIRST_GOAL)
	local CLOSED_STATUS = TweenService:Create(Door, TweenInfo, GOALS.SECOND_GOAL)
	return {OPEN_STATUS;CLOSED_STATUS}
end
return DOOR_TWEEN_SERVICE

Now this is good only if the Door’s hinge is at a 0 Degree orientation, say if it were at something like 45, it won’t work cleanly, like in the gif below
https://gyazo.com/ede118109c45becb2832ba251fcb2cfc
How would I go about making it so that in the module, it multiplies it’s hinge CFrame till it reaches 90 Degrees so it’ll work even at different orientations the hinge is at?

1 Like

So, if I get you correctly, you want the door to close back in the way it opened? Try adding a debounce to check if the door is opened.

1 Like

The door’s main system’s like opening, closing, etc are already done, I’m having problems with the Tweening of it’s hinge because it’s moves the door to completely different positions if the door model itself is rotated, and so the hinge’s CFrame also gets changed, which I think is causing that.

https://gyazo.com/25f04b5e58645fda8a4dd87cf9d724fb Hopefully this gif adds on to what I mean by it.

1 Like

what if you changed this

SECOND_GOAL = {CFrame = CFrame.new(Door.Position) * CFrame.Angles(0, math.rad(-180), 0)}

to

SECOND_GOAL = {CFrame = CFrame.new(Door.Position) * CFrame.Angles(0, math.rad(180), 0)}

?

1 Like

I’ve fixed the issue now, though thank you for the help!

1 Like