Hitbox causes player to take damage more than once

I want it to be when the player touches the hitbox then they’re name will be put in a table and they will be blacklisted from taking damage again until the cooldown is done, however the problem is that when I try this the player still takes multiple damage (for each part of the character)

--This is section of script with the issue


local Blacklist = {}
		local HitParts = workspace:GetPartBoundsInBox(Hitbox.CFrame, Hitbox.Size, overlapParams)
		for _, Part in pairs(HitParts) do
			local Humanoid = Part.Parent:FindFirstChild("Humanoid")
			if Humanoid and not Part:IsDescendantOf(Character) then
				local EnemyHumanoid = Humanoid
				local EnemyCharacter = EnemyHumanoid.Parent
				local EnemyRootPart = Character:FindFirstChild("HumanoidRootPart")
				if not Blacklist[EnemyHumanoid ] then
					Blacklist[EnemyHumanoid ] = true
					EnemyHumanoid :TakeDamage(BaseDamage)
					wait(1)
					if Blacklist[EnemyHumanoid ] then
						Blacklist[EnemyHumanoid ] = nil
					end
				end
			end
		end

You’re using EnemyHumanoid as the index instead of a number. Use this to get the index:

table.find(Blacklist, EnemyHumanoid)

If it returns nil, the object wasn’t in the table. If the object is in the table, it will return it’s index.

local Blacklist={}
local HitParts=workspace:GetPartBoundsInBox(Hitbox.CFrame,Hitbox.Size,overlapParams)
for _,Part in ipairs(HitParts)do
    local Humanoid=Part.Parent:FindFirstChild("Humanoid")
    if Humanoid and not Part:IsDescendantOf(Character)and not Blacklist[Humanoid]then
        Blacklist[Humanoid]=true;Humanoid:TakeDamage(BaseDamage)
        delay(1,function()Blacklist[Humanoid]=nil end)
    end
end

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