In the example, the tween is created using the TweenService’s Create function. The syntax is:
TweenService:Create(instance, tweenInfo, propertyTable)
The propertyTable
is a table where the keys are the names of the properties you want to tween, and the values are the final values you want those properties to have when the tween finishes. For instance:
TweenService:Create(part, info, {Position = Vector3.new(0, 50, 0), Transparency = 1})
In this case, the Position
property of part
will be tweened to Vector3.new(0, 50, 0)
and the Transparency
will be tweened to 1
.
In your case, you want the CFrame of the part to be tweened to the CFrame that looks at the mouse, so you use:
local cf = CFrame.lookAt(part.Position, mouse.Hit.p)
local tween = TweenService:Create(part, info, {CFrame = cf})
So the CFrame
of the part
will be tweened to the cf
variable, which is set to the CFrame that looks at the mouse’s position.
Now, to your second question
In this context, you are defining the desired CFrame for the tool part to be tweened to. You are effectively saying, “I want the part’s CFrame to become this over a set duration and easing style.”
In the following line:
local cf = CFrame.lookAt(part.Position, mouse.Hit.p)
cf
is assigned a CFrame that points from your tool’s position (part.Position
) to the mouse’s current 3D position (mouse.Hit.p
). The lookAt()
function generates a CFrame oriented towards the point you passed in.
You then pass cf
to the Tween function like this:
local tween = TweenService:Create(part, info, {CFrame = cf})
This will apply a tween to the part that changes its CFrame such that it smoothly transitions to the CFrame you specified (cf
), over the specified time and using the defined easing style. The part’s PrimaryPart CFrame (if the parent is a Model) does not need to be explicitly specified for this operation, as it is automatically calculated by Roblox.