Converting :Lerp to a tween

Hello!
So I am currently trying to make a simple FPS game to practice development and ive came into a issue. Using the tutorial that ive used to assist me they use :Lerp to change the position of the gun. I found that lerp works but not very well, its a bit buggy and does not always play correctly. The goal is to convert to tweens.

When the player begins to sprint:

sprintcf = sprintcf:Lerp(WeaponData.SprintCFrame,0.2)

WeaponData.SprintCFrame referring to the module script that has

module.SprintCFrame = CFrame.new(-0.5,-0.25,0) * CFrame.Angles(0,math.rad(55), 0)

For converting this into a tween ive come into an issue.

local TI = TweenInfo.new(0.2)
	local tween = Tween:Create(sprintcf, TI, WeaponData.SprintCFrame)
	tween:Play()

Ive tried some different variations of this and none seem to work. Could I get some help?
Thanks,

  • Alex
1 Like

The TweenService:Create function requires an Instance to manipulate - not a variable (sprintcf).

For example - you can manipulate the CFrame of a Part using the TweenProperties:

local part = game.Workspace.Part
local tweenInfo = TweenInfo.new(0.2)
local tweenProperties = { CFrame = CFrame.new(0, 5, 0) }
local tween = Tween:Create(part, tweenInfo, tweenProperties)
tween:Play()

but you cannot do the same to a variable.

Lerps are also usually used in junction with a loop as well, because, looking at your code, Lerp(cf, 0.2) will only get you 20% to your desired cframe if you called it one time.

Whereas Tweening will run in its own loop toward the desired values.
So if you have a loop using the Lerp at the moment, you’ll need to swap that out.

1 Like