How to make a good melee? with a good hitbox

So, I have a hitbox for my melee but it seems to not have good accuracy this is what I have for my script

rs.Remotes.Melee.OnServerInvoke = function(plr,tool)
	if not debounce[plr.UserId] and tool and game.ServerStorage.Tools:FindFirstChild(tool.Name) then
		debounce[plr.UserId] = true
		local stats = require(game.ServerStorage.Tools[tool.Name].Stats)
		if tool:FindFirstChild("Handle") and tool.Handle:FindFirstChild("Sound") then
			tool.Handle.Sound:Play()
		end
		if tool:FindFirstChild("Hitbox") then
			for i,v in pairs(GetTouchingParts(tool.Hitbox)) do
				if v.Parent ~= plr.Character and game.Players:GetPlayerFromCharacter(v.Parent) then return end
				if v.Parent ~= plr.Character and v.Parent:FindFirstChild("Humanoid") then
					v.Parent.Humanoid:TakeDamage(stats.damage)
				end
			end
		end
		wait(stats.rate)
		debounce[plr.UserId] = false
	end
end

My hitbox is like this

3 Likes

What I would do is maybe increase the hitbox some more. Because if the hitbox is a bit bigger the hit is more likely to register. Or you could make it when you swing the sword it fires a ray towards the nearest player from the blade and if it is within a Stud range it registers as a hit.

1 Like

Well, I think part of the problem is that you are using get touching parts one the server side which ultimately “creates” a delay in between when you are swinging the sword and from when it actual registers

Also If you haven’t already I would check this out:
( for accuracy stuff)

2 Likes

It looks like your remote event only fires once the player starts swinging, right? If that is the case, then your function is only checking for collisions one time when the swing begins. This means it’s most likely that the sword isn’t even colliding with the enemy yet.

I would instead check for colliding parts in a repeated loop until the swing animation is done (it would probably be best to record the length of the animation on the server so that there is no delay for sending when the swing completes).

I also think it would be easier to just connect a Touched event and then disconnect it once the swing ends as mentioned above.

Edit: Another important factor is that GetTouchingParts only works if said part is CanCollide - true or has a TouchInterest. If it is CanCollide - false then you have to create a Touched event in order to create a TouchInterest.

2 Likes

This is going to damage the player for every part the sword is touching, which could be multiple parts of their body; meaning they would take 2-3+ times the amount of damage you intend. You should break the loop once the player is damaged, or if you want it to be possible to damage multiple players, then save each player in the loop that gets damaged and use an if statement to ensure the player hasn’t already been damaged.

I’m not sure why people make hit boxes. You can raycast (per step) the blade horizontally, vertically or both and find the magnitude from two vectors (blade and where it hit). If magnitude < 1, deal damage.

Works best if you use CFrames to animate or, procedural animation.

2 Likes

how would i use this with my remote?

it depends, if you were using the Raycast module by Swordphin you could either probably run the checks on the server or the client, if you were to intend to run the “hit checks” on the client, you could fire a remote function containing the parts the was hit ( i wouldn’t recommend firing a remote function and then checking if it is touching a player our whatever , as that could create a possibly delay as i stated above)

local RaycastHitbox = require(RaycastHitboxModule)

local NewHitbox = RaycastHitbox:Initialize(script.Parent.Model)

NewHitbox.OnHit:Connect(function(hit, humanoid)
--- code, fire the remote function
end)

NewHitbox:HitStart()

isn’t the client exploitable? I know hitboxes might be able to be exploited since if you edit the module on the client u may be able to exploit it like if u do client detection