Why isn't the hitbox constantly damaging any victims?

Hello There!

I’m having an issue with a hitbox for a firey vomit attack. For a more detailed explanation, I’m recreating one of the attacks of a Battle Brick’s boss, being Turking which he’ll eat a turkey leg with epic sauce (Which is basically hot sauce) and vomit a firey breath.

As the issue says, I have a hitbox which appears in front of the player while they vomit which will constantly deal damage towards anyone within the firey vomit, the issue is that they only get damaged once and not constant.

(This is the code where the hitbox spawns and the damage script.)

local BarfingHitBox = Instance.new("Part",game.Workspace)
	
	BarfingHitBox.Size = Vector3.new(5, 7, 14)
	BarfingHitBox.Anchored = true
	BarfingHitBox.Transparency = 1
	BarfingHitBox.CanCollide = false
	
	local Hits = {}
	
	BarfingHitBox.Touched:Connect(function(OnHit)
		local Character = OnHit:FindFirstAncestorWhichIsA("Model")
		local Humanoid = Character and Character:FindFirstChildWhichIsA("Humanoid")
		if Humanoid and Character ~= Plr.Character and not Hits[Character] then
			Hits[Character] = true
			Humanoid:TakeDamage(8.5)
			task.wait(.05)
			Hits[Character] = false
		end
	end)
1 Like

If you want it to be constant over a period, use :GetPartsInPart in a loop. I’ve also optimized it by excluding Plr.Character in the parts search.

Code:

local BarfingHitBox = Instance.new("Part")
BarfingHitBox.Size = Vector3.new(5, 7, 14)
BarfingHitBox.Anchored = true
BarfingHitBox.Transparency = 1
BarfingHitBox.CanCollide = false
BarfingHitBox.Parent = workspace

local Hits = {}

--//Ignore objects that are part of the player vomitting
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Exclude
overlapParams.FilterDescendantsInstances = {Plr.Character}

--//100 is the amount of times the attack will register
for i = 1, 100 do
	for i, part in workspace:GetPartsInPart(BarfingHitBox, overlapParams) do
		local Character = part.Parent
		local Humanoid = Character and Character:FindFirstChildWhichIsA("Humanoid")
		
		if Humanoid and not Hits[Character] then
			Hits[Character] = true
			Humanoid:TakeDamage(8.5)
		end 
	end
	
	table.clear(Hits)
	task.wait(.05)
end

It works! Although I did had to change it a bit, but still, thank you!

1 Like

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