Answered by
6 years ago Edited 6 years ago
Why use p instead of Position?
CFrame.p
and CFrame.Position
are identical, though the former is deprecated in favour of the latter.
does this define both, the player that got hit and the position of that player?
Workspace:FindPartOnRay
returns the BasePart hit and the Vector3 point of intersection (the precise position (in world space) that the Ray hit). This could be useful to know where to place a bullet hole, for example.
Purpose of magnitude?
Vector3.Magnitude
returns the magnitude/distance of a Vector3 (as a number). In this case, it is used to get the distance between the Tool's handle and the point of intersection.
Purpose of distance on the z-axis?
The distance variable, which we previously worked out is the distance between the Tool's handle and the point of intersection, is used as the Z component of beam's Size. This will make beam stretch the entire distance (with the correct direction and position, which we see later) between the Tool's handle and the point of intersection.
What does the -distance/2 on the z-axis do?
The -distance/2
is offsetting beam so that it starts at the Tool's handles CFrame on the Z axis.
is this line necessary?
This line appears to be unnecessary. I would return from the function instead to avoid pointless if statements later down the line.