Hitbox that only hits one person

I want to make a hitbox that only hits only one person thats caught in it.

Currently I have a grab skill that, when multiple people are caught in the hit box it grabs everyone individually. But I only want it to grab one person.

Ive been at this for hours and tried so many things😭

local HitList = dmgTable
	local hits = dmgTable

		local CurrentFrame = HumanoidRootPart.CFrame
		if player then
			CurrentFrame = SharedFunctions.GetRootCFrame(player)
		end
    	local overlapParams = OverlapParams.new()
	local hitContents = HitBoxManager:Box(CurrentFrame * CFrame.new(0,0,-3),Vector3.new(8,8,8),player, overlapParams)
		
			for i,Enemy in pairs(hitContents) do
				if Enemy ~= Character and not table.find(HitList, Enemy) then
					local v = TagHumanoid:TagHumanoid(Character, Enemy, dmgTable,)
					table.insert(HitList, Enemy)
		          	table.insert(hits, v)

Just break out of your loop once you identify an enemy so that you would only attack that one person

or is there something im not understanding correclty here/

If i run the break command too early its also gonna ask for a “end” and then the script wont be able to identify what “Enemy” is anymore. Where should i put the break get around this? Or is there another solution i could do. Also the script detects all the enemies that got caught in the hitbox.

Don’t use a hitbox, use a raycast and shoot it from the HRP’s lookvector. That way, it’ll hit the player that the character is looking at. And not other people.

The whole entire game has already been based around hitboxes i cant rlly go back from that now😭, id rather just find a solution where i can continue to use hitboxes

You could try whitelisting the first object that is found in the for loop since it goes in order through overlap params.

Why would you be trying to access “Enemy” after breaking out of your script anyways? all enemies you want should already be stored in that HitList table you created.

(wdym “ask for an end”, like is it giving you a missing “end” error or do you just mean its trying to finish something but it can’t?)

The problem fixed itself, I rlly dont know how :sob:, Thank you all for helping though

1 Like