Updating Tween while its playing

Hey guys, i’m unable to get the the tween to update while its playing. I’m using the tween for the recoil, and when i move while shooting it causes weird issues, as shown below:


Here’s the code i made for it:

		local Camera = workspace.CurrentCamera
		--Camera.CameraType = Enum.CameraType.Scriptable
		
		
		local goal = {}
		goal.CFrame = Camera.CFrame*CFrame.Angles(math.rad(4,6), math.rad(1,2), 0)

		local tweenInfo = TweenInfo.new(0.1)

		local tween = TweenService:Create(Camera, tweenInfo, goal)

		tween:Play()

Can anyone help me with making it update while playing, or if i should do something else? Thanks for all help in advance!

		local Camera = workspace.CurrentCamera
		--Camera.CameraType = Enum.CameraType.Scriptable
		local frameLength = 10; -- Amount of frames to use for recoil.
                local x, y = 4.6, 1.2;

		local addX, addY = x / frameLength, y / frameLength;

		for i = 0, frameLength, 1 do
			Camera.CFrame = Camera.CFrame*CFrame.Angles(math.rad(addX), math.rad(addY), 0);
		end;

This would do the same thing while respecting modifications, I think this is the bug that you wanted to fix, if not, please clarify.
EDIT: Fixed @kingdomkind

			Camera.CFrame = Camera.CFrame*CFrame.Angles(math.rad(addX)), math.rad(addY)), 0);

This line is highlighted and gives the error of " Expected identifier when parsing expression, got ‘)’". I don’t see where an extra bracket is though. Also thanks for your help!

Fixed, check above. not enough chars

It works now, but it brings me back to square one with making the recoil smooth, here’s a clip:


Is there a way i can preserve the smoothness of the tween while updating it? I’ve heard on other posts that to use lerp.

Oh my mistake completely forgot a part of the code:

		local Camera = workspace.CurrentCamera
		--Camera.CameraType = Enum.CameraType.Scriptable
		local frameLength = 10; -- Amount of frames to use for recoil.
                local x, y = 4.6, 1.2;

		local addX, addY = x / frameLength, y / frameLength;

		for i = 0, frameLength, 1 do
			Camera.CFrame = Camera.CFrame*CFrame.Angles(math.rad(addX), math.rad(addY), 0);
			game:GetService("RunService").RenderStepped:Wait(); -- Waits a frame.
		end;
1 Like

Thanks, this works perfectly! Thanks for your assistance once again!

1 Like