So I use magnitude when I want to make combat, but the hardest part when it comes to making combat is making sure the hitbox is perfect. How can I make it so magnitude doesn’t hit a player from behind your character? Here’s an example:

if (humanoidroot1.Position - humanoidroot2.Position).magnitude < 5 then
--damageplayer
end

As you can see this checks the distance between the two, but it will still work if a player is behind you while you’re clicking and it will still damage if they’re in range.

The dot product is useful here. By calculating the vector from 1 to 2, and then checking it’s dot with the lookvector of 1, you can check whether the two vectors point in the same or opposite directions.

Positive dot = within 90 degrees of each other.
Zero dot = exactly perpendicular.
Negative dot = within 90 degrees of being opposite to each other.

By checking the dot is above zero, and only applying the damage in this scenario, you ensure 2 is in front of 1.

local vector = humanoidroot2.Position - humanoidroot1.Position
if vector:Dot( humanoidroot1.CFrame.lookVector ) > 0 then
-- humanoidroot2 is in front of humanoidroot1
end

You should probably use something like local c = OtherPlayerCFrame:FromObjectSpace(HRP.CFrame)
and then check if the z is negative
if c.Z > 0 then
–Code here
end