Detecting multiples parts of a rig and doing more damage than it should

Im trying to make a tool that summons a hitbox, check the parts inside the hitbox and then deal the damge, but i am with a problem, when it detect more parts of the body it deals the damage again like, i set the damage to 10, if it hits only the arm it deals 10 damage, but if it gets the arm and the torso it deals 20, i dont want this, i want only to 10 dont matter how many parts of the same body it gets

Here is the script:

local evento = game.ReplicatedStorage.Weapons.Axe.Damage
local runservie = game[“Run Service”]
local debris = game.Debris

evento.OnServerEvent:Connect(function(player, hit)
wait(0.25)
local character = player.Character
local rootpart = character:WaitForChild(“HumanoidRootPart”)
local hitbox = game.ReplicatedStorage.Weapons.Axe.Damage.AxeBox:Clone()
hitbox.Parent = workspace.Ignore
hitbox.CFrame = rootpart.CFrame * CFrame.new(0,0, -3)
local damage = game.ReplicatedStorage.Weapons.Axe.Damage.Damage.Value

local socoOverlapParams = OverlapParams.new()
socoOverlapParams.FilterType = Enum.RaycastFilterType.Blacklist
socoOverlapParams.FilterDescendantsInstances = {workspace.Ignore,character}

local hitpart = workspace:GetPartsInPart(hitbox,socoOverlapParams)

if #hitpart ~= 0 then
    local hitou = {}
    for i, v in pairs(hitpart) do 
        local humanoid = v.Parent:FindFirstChild("Humanoid")
        if humanoid then
            if not table.find(hitou,humanoid) then
                humanoid:TakeDamage(5)
            end
        end
    end
end
debris:AddItem(hitbox, 0.1)

end)

1 Like
if #hitpart ~= 0 then
	local hitou = {}
	for i, v in pairs(hitpart) do 
		local humanoid = v.Parent:FindFirstChild("Humanoid")
		if humanoid then
			if not table.find(hitou,humanoid) then
				humanoid:TakeDamage(5)
				break
			end
		end
	end
end

break the for loop once a humanoid is detected

but with this way if there is more than one humanoid it will only hit one

it looks like you’re using ‘hitou’ as a list of humanoids that were already hit by the tool, and thus should be ignored. all you forgot to do was add the humanoid to the list after making them take damage.

local hitpart = workspace:GetPartsInPart(hitbox,socoOverlapParams)

if #hitpart ~= 0 then
    local hitou = {}
    for i, v in pairs(hitpart) do 
        local humanoid = v.Parent:FindFirstChild("Humanoid")
        if humanoid then
            if not table.find(hitou,humanoid) then
                humanoid:TakeDamage(5)
                table.insert(hitou,humanoid)
            end
        end
    end
end
debris:AddItem(hitbox, 0.1)

end)

1 Like

Tysm, i accidently deleted this line earlier lol
I was asking myself why it wasnt working right anymore lol