How do I ignore my humanoid?

I am working on a hitbox script it works and does damage but if the player who creates the hitbox is touching it, it does not do damage to anyone, is there a way I can ignore the local player? It also does damage to only 1 humanoid not all in the hitbox.

Script:

local function createhitbox()
	local hitboxdb = false
	
	local hitbox = Instance.new("Part")
	hitbox.Parent = workspace
	hitbox.Anchored = true
	hitbox.CanCollide = false
	hitbox.Size = Vector3.new(10,1,10)
	hitbox.Transparency = 0.5
	hitbox.CFrame = hrp.CFrame * CFrame.new(0,0,-4)
	
	hitbox.Touched:Connect(function(hit)
		if hitboxdb == false then
			hitboxdb = true
			local enemycharacter = hit.Parent
			print(enemycharacter)
			local hithumanoid = enemycharacter:FindFirstChild("Humanoid")
			if hithumanoid == hum then
			else
				hithumanoid:TakeDamage(5)
			end
			task.wait(0.5)
			hitboxdb = false
		end
	end)
	wait(0.1)
	hitbox:Destroy()
end
2 Likes

Wait, what is hum whos humanoid is it?

if hit:IsDescendantOf(hum.Parent) then return end

It also does damage to only 1 humanoid not all in the hitbox.

The reason this happens is because of the task.wait(0.5) before you toggle the hitboxdb. To fix this, add the humanoid the player hits to a table after it’s been damaged, and then when it tries to damage a humanoid again, check to see if the humanoid is in the table, if it is, do nothing. This will make sure an enemy is only damaged once per hit. Make sure to remove the humanoid from the table, by using task.delay(), with a delay of 0.5 seconds and table.remove().

I wrote this quickly, so bits of it may be hard to understand, if you need anything clearing up, let me know.

1 Like