Better way to detect hits for a combat system

Hello,
I want to find a better way to detect hits rather than using Touched events as they can be a bit buggy sometimes, in my current Combat system I made I’m using the touched event, for bigger weapons it sometimes registers and sometimes it doesn’t regardless of how big the hitbox is, I’ve tried ray casting although I’m not the most experienced scripter regarding raycasting, With the little knowledge I have I simply used the LookVector of the HumanoidRootPart and casted a ray if it gets touched it damages, but that also was a bit buggy and sometimes it didnt hit, If anyone got any solution or a better way to get around this thing I’d appreciate it.

Here’s the current Touched event code that is used to manage the damage:

-- Local Side:
-- >>: FireServer function
local function FireServer(remotename, data)
	local remote = script.Parent:FindFirstChild(remotename)
	remote:FireServer(data)
end


-- >>: Touched
script.Parent.Parent.Parent.Blade.Touched:Connect(function(Hit)
	local hum = Hit.Parent:FindFirstChild("Humanoid")
	if hum and hitting == true and Parrying == false then
		print("Hit")
		hitting = false
		FireServer("Manage", {"Damage", hum.Parent})
	elseif Hit.Name == "Block" and hitting == true and Parrying == false then
		local vchar = Hit.Parent.Parent
		local vplayer = game.Players:FindFirstChild(vchar.Name)
		
		if vplayer.Mark.Blocking.Value == true then
			print("Blocked")
			hitting = false
			FireServer("Manage", {"Blocked"})
		end
	end
end)


-- Server Side:

-- >>: Damage Function
local function DamageF(char)
	local humanoid = char.Humanoid
	
	if tonumber(humanoid.Health) > Damage.Value then
		humanoid.Health = tonumber(humanoid.Health) - Damage.Value
		char.Head.Hit:Play()
	elseif tonumber(humanoid.Health) <= Damage.Value then
		humanoid.Health = 0
		char.Head.Hit:Play()
	end
end

-- Script that calls the function (Inside of a OnServerEvent Event)
        local Status = data[1]
	if Status == "Damage" then
		DamageF(data[2])
	elseif Status == "Blocked" then
		Player.Character.Head.Block:Play()	
	end

Here’s a GIF showing the problem I’m facing:
https://gyazo.com/d63a8d7f209e3f520419228fa8cc5b6c

This is how everything is organized:
https://gyazo.com/d0a8ba8291493979dfa201a2262395a7

When the heavy weapons hitbox doesn’t damage no errors pop up in the output, simply poor hit detection.

I would recommend using raycasting for this.

There is a great module already made for you on devforum: Raycast Hitbox 4.01: For all your melee needs!

2 Likes