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