Need help making continuous damaging hitbox

I need help with making my hitbox damage players continuously even when they are standing. How do I do this?

hitbox.HumanoidCollided:Connect(function(RaycastResult, HitHumanoid)
	if Debounce[HitHumanoid] then
		return
	end

	if HitHumanoid == character.Humanoid then return end
	if HitHumanoid.Health == 0 then return end

	Debounce[HitHumanoid] = true

	HitHumanoid:TakeDamage(Settings.RangeDamage)

	task.wait(Settings.RangeCooldown)
	Debounce[HitHumanoid] = false
end)

I’m not sure what you meant by that.

But for a hitbox that damages players continously, you could use CollectionService.
You just make a script that waits until a tag is added (‘hitbox’ for example), and then damages the player until the tag is removed or the player is dead.
Adding and removing the tag is based on if the char is within the hitbox

Think about it like a damage brick, normal damaging bricks do not damage the player constantly when they are standing still. I want to damage the player repeatedly until they are dead or not touching the hitbox

Yes, that’s what my example would do.
1196dbff70a53bb2c430fa411e27d390
When a part has ‘hitbox’, it damages the humanoid over time.

local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")


local DAMAGE_PER_TICK = 5
local DAMAGE_INTERVAL = 1 

CollectionService:GetInstanceAddedSignal("hitbox"):Connect(function(obj)
	local humanoid = obj.Parent and obj.Parent:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end

	local alive = true
	local tagRemoved = false

	local function onRemoved()
		tagRemoved = true
	end

	local removalConn = CollectionService:GetInstanceRemovedSignal("hitbox"):Connect(function(instance)
		if instance == hitbox then
			onRemoved()
		end
	end)


	task.spawn(function()
		while alive and not tagRemoved do
			if humanoid.Health <= 0 then
				alive = false
				break
			end

			humanoid:TakeDamage(DAMAGE_PER_TICK)
			task.wait(DAMAGE_INTERVAL)
		end

		removalConn:Disconnect()
	end)
end)

Now this isn’t perfect. You’d need to do the logic for adding/removing the ‘hitbox’ tag. And that logic needs to ensure it only adds ‘hitbox’ to one child of character, like humanoidrootpart. Because right now if you add hitbox to 2 bodyparts, it’ll do 2x damage

1 Like

Forgive me if I’m wrong, but wouldn’t using a tag added to the player’s character be exploitable? Could an exploiter simply remove the hitbox tag whenever it was added? And if so, how would you defend against that because I assume you can’t just keep continuously checking for the tag.

It’s done on the server. If you read the code, it answers your question. It doesn’t keep checking for the tag; it connects and disconnects based on the tag being added or removed

1 Like

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