Magnitude and Raycast hitbox problem

So I am making a hitbox system for a melee tool. I am using magnitude and raycasting for the hitbox. So basically I looped through all of the player character in the workspace and find which character is in range and then I use raycast to make sure if that player is in the front or not. The script works fine but the problem is that the enemy have to be exactly in front to be hit, because of the raycast, I want it the hitbox to be a little more wide, how would I do that?

local MagnitudeHitbox = {}

function MagnitudeHitbox.Hit(Humrp, Dmg, Range, Knock)
	for i,v in pairs(game.Workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") then
			local EHumrp = v:FindFirstChild("HumanoidRootPart")
			local EHum = v:FindFirstChild("Humanoid")
			if EHumrp and EHum then
				if EHumrp ~= Humrp.Parent:FindFirstChild("HumanoidRootPart") then
					if (Humrp.Position - EHumrp.Position).magnitude <= Range then
						print("In range")
						
						local RayDetect = Ray.new(Humrp.Position, Humrp.CFrame.LookVector * Range)
						local hit,position = game.Workspace:FindPartOnRayWithIgnoreList(RayDetect, {Humrp.Parent})
						
						if hit then
							print("Took Damage")
							EHum:TakeDamage(Dmg)
						end
					end
				end
			end
		end
	end
end

return MagnitudeHitbox

Do you create the Magnitude Hiitbox or is the magnitude Hiitbox just the humanoidrootpart?

(I haven’t tested this)
If it is just the humanoidrootpart, then why not create a new,bigger,non-collidable part and weld it to the humanoidrootpart, and set that as the hitbox instead.

Hello, if you want to get the angle between 2 vectors (front position of the player and enemy direction), you could have googled it, but I have made a formula for you and for everyone else

local v1 = Vector3.new(1,1,1)
local v2 = Vector3.new(1,0,0)
print(math.acos(v1:Dot(v2) / (v1.Magnitude * v2.Magnitude))) -- returns value in radians
print(math.deg(math.acos(v1:Dot(v2) / (v1.Magnitude * v2.Magnitude)))) -- returns value in degrees (translates from radians to degrees)

Please note that the numbers aren’t perfect and may slightly differ from the real angle due to the way how computers perform math operations