My tweening is not working correctly

Hello,
I’m doing a tween with a lever that activate/Disactivate the lever. When I click on it, to activate it, no problem. But when I click on the lever to disactivate it, it does this :

Here is the part of the code that handle the tween :

script.Parent.Parent.Parent.Lever.Union.ClickDetector.MouseClick:Connect(function()
	if debounce == false and leverLocked == false then
		debounce = true 
		tween:Create(CF, TweenInfo.new(3, Enum.EasingStyle.Quart),    {Value = center.CFrame * CFrame.Angles(math.rad(165),math.rad(0),math.rad(0))}):Play()
		statut.Text =  "Warhead: Enabled"
		if activated == false then
			timerGoDown = true
			Theme:Resume()
			Theme.Volume = 0
			for i = 0,0.5,0.01 do
				Theme.Volume = Theme.Volume + i/20
				wait(0.01)
			end

			coroutine.wrap(function()
				for i = 1, Timer do
					if not timerGoDown then break end
					screen.DetonationNumLabel.Text = Timer.. " seconds"
					wait(1)
					Timer = Timer - 1
				end

				if Timer == 0 or Timer == 1 then

					for _, part in pairs(game.Workspace:FindPartsInRegion3(Region,nil,math.huge)) do
						local hum = part.Parent:FindFirstChild("Humanoid")
						if not hum then continue end
						hum.Health = 0
					end
					screen.DetonationNumLabel.Text = "Detonated"
					for i = 0,0.5,0.01 do
						Theme.Volume = Theme.Volume - i/20
						wait(0.01)
					end
					Theme:Stop()
					script.Disabled = true
				end
			end)()
			wait(coolDown)
			activated = true
		else
			timerGoDown = false
			Timer = Timer
			Theme:Pause()
			for i = 0,0.5,0.01 do
				Theme.Volume = Theme.Volume - i/20
				wait(0.01)
			end
			statut.Text =  "Warhead: Disabled"
			tween:Create(CF, TweenInfo.new(3, Enum.EasingStyle.Quart),    {Value = center.CFrame * CFrame.Angles(math.rad(35),math.rad(0),math.rad(0))}):Play()
			wait(coolDown)
			activated = false
		end
		wait(1)
		debounce = false
	end
end)

Try setting the angle to -165 instead of 35 for when you deactivate it, since it’s adding 35 to the angle already set when disabling

It was by default on -165, but it did the same thing, even more glitchy cuz the lever disappeared in the wall.

Maybe put a variable containing the CFrame of the center thing before doing any tweening, and when tweenign it off, jsut use that instead

local centerCF = center.CFrame

script.Parent.Parent.Parent.Lever.Union.ClickDetector.MouseClick:Connect(function()
	if debounce == false and leverLocked == false then
		debounce = true 
		tween:Create(CF, TweenInfo.new(3, Enum.EasingStyle.Quart),    {Value = centerCF * CFrame.Angles(math.rad(165),math.rad(0),math.rad(0))}):Play()
		statut.Text =  "Warhead: Enabled"
		if activated == false then
			timerGoDown = true
			Theme:Resume()
			Theme.Volume = 0
			for i = 0,0.5,0.01 do
				Theme.Volume = Theme.Volume + i/20
				wait(0.01)
			end

			coroutine.wrap(function()
				for i = 1, Timer do
					if not timerGoDown then break end
					screen.DetonationNumLabel.Text = Timer.. " seconds"
					wait(1)
					Timer = Timer - 1
				end

				if Timer == 0 or Timer == 1 then

					for _, part in pairs(game.Workspace:FindPartsInRegion3(Region,nil,math.huge)) do
						local hum = part.Parent:FindFirstChild("Humanoid")
						if not hum then continue end
						hum.Health = 0
					end
					screen.DetonationNumLabel.Text = "Detonated"
					for i = 0,0.5,0.01 do
						Theme.Volume = Theme.Volume - i/20
						wait(0.01)
					end
					Theme:Stop()
					script.Disabled = true
				end
			end)()
			wait(coolDown)
			activated = true
		else
			timerGoDown = false
			Timer = Timer
			Theme:Pause()
			for i = 0,0.5,0.01 do
				Theme.Volume = Theme.Volume - i/20
				wait(0.01)
			end
			statut.Text =  "Warhead: Disabled"
			tween:Create(CF, TweenInfo.new(3, Enum.EasingStyle.Quart),{Value = centerCF}):Play()
			wait(coolDown)
			activated = false
		end
		wait(1)
		debounce = false
	end
end)
1 Like