Why do some hits miss?

For some reason, some of the hits miss. Even though it’s CLEARLY hitting the character.
I think it might be related to the hitbox hitting the other player’s weapon, but I don’t really know how to fix it.
I know filterparams exists. but I don’t know how to filter the other player’s weapon using it.
The hitbox is infront of the weapons:
image
Here is the script:

local tool = script.Parent.Parent
local handle = tool:WaitForChild("Handle")
local stab = tool:WaitForChild("Stab")
local debris = game:GetService("Debris")

-- Configurations
local config = script.Parent.Parent.Inact:WaitForChild("Configuration")
local kitchenknife = config:WaitForChild("KitchenKnife")

local animid = kitchenknife.Animation
local cd = kitchenknife.Cooldown
local damage = kitchenknife.Damage

local humdeb = false
local params = OverlapParams.new()
params.FilterDescendantsInstances = {
	script.Parent.Parent.Parent,
	script.Parent.Parent:FindFirstChild("Handle", true),
	script.Parent,
	script.Parent.Parent.Handle
}
params.MaxParts = 100
tool.Activated:Connect(function()
	local char = script.Parent.Parent.Parent
    local plr =	game.Players:GetPlayerFromCharacter(char)
	local multiplier = plr.DamageMultiplier
	local smultiplier = plr.RateMultiplier
	local parts = workspace:GetPartBoundsInBox(script.Parent.CFrame, script.Parent.Size, params)
	if parts then
		for i,v in pairs(parts) do
			if v.Parent:FindFirstChild("Humanoid") and humdeb == false then
				local tag = Instance.new("ObjectValue")
				tag.Name = "tag"
				tag.Value = plr
				tag.Parent = v.Parent.Humanoid
				debris:AddItem(tag, .5)
				print(tag.Name)
				humdeb = true
				v.Parent:FindFirstChild("Humanoid"):TakeDamage(damage.Value * multiplier.Value)
				task.wait(cd.Value * smultiplier.Value)
				humdeb = false
				break
			else
				return	
			end 			
		end
		task.wait()
		end
	end)


(The coins are meant to go up when damage is dealt and I know for a fact there’s no problem with the script for making coins increase)

Can anybody help me with this?

did you turn off CanTouch thing?

No I didn’t turn off can touch, this script doesn’t use touched event anyways so it wouldn’t matter

Your current script sets up OverlapParams but may not effectively exclude all irrelevant parts…
So I used Enum.RaycastFilterType.Exclude to do that

local tool = script.Parent.Parent
local handle = tool:WaitForChild("Handle")
local stab = tool:WaitForChild("Stab")
local debris = game:GetService("Debris")

-- config
local config = script.Parent.Parent.Inact:WaitForChild("Configuration")
local kitchenknife = config:WaitForChild("KitchenKnife")

local animid = kitchenknife.Animation
local cd = kitchenknife.Cooldown
local damage = kitchenknife.Damage

local humdeb = false

-- create OverlapParams with the necessary filters
local function createOverlapParams()
	local params = OverlapParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {
		script.Parent.Parent.Parent,  -- player's char
		tool,  -- self explanatory
		tool:FindFirstChild("Handle", true),  -- self explanatory
		script.Parent  -- hitbox part
	}
	params.MaxParts = 100
	return params
end

local params = createOverlapParams()

tool.Activated:Connect(function()
	local char = script.Parent.Parent.Parent
	local plr = game.Players:GetPlayerFromCharacter(char)
	local multiplier = plr.DamageMultiplier
	local smultiplier = plr.RateMultiplier
	local parts = workspace:GetPartBoundsInBox(script.Parent.CFrame, script.Parent.Size, params)

	if parts then
		for _, v in pairs(parts) do
			local humanoid = v.Parent:FindFirstChild("Humanoid")
			if humanoid and not humdeb then
				local tag = Instance.new("ObjectValue")
				tag.Name = "tag"
				tag.Value = plr
				tag.Parent = humanoid
				debris:AddItem(tag, 0.5)
				print(tag.Name)
				humdeb = true
				humanoid:TakeDamage(damage.Value * multiplier.Value)
				task.wait(cd.Value * smultiplier.Value)
				humdeb = false
				break
			end
		end
	end
end)

Hope this helps

1 Like

Thank you! I never knew Enum.RaycastFilterType.Exclude existed until now!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.