Explosion hitbox hits multiple times

I’ve been using MuchachoHitbox for my game and I have it set up so an explosion is created and for each humanoid in the hitbox, it deals 25 damage. MuchachoHitbox has a built in way of checking if a humanoid has been hit before (setting detection mode to Default) but for some reason, my touched event fires twice. I presume it’s because there are 2 humanoids in the hitbox and its calling .Touched for each one but I don’t know how to make it only call one time. Changing the DetectionMode to “HitOnce” doesn’t work because then it just straight up doesn’t damage anything.

HELP!
My code (screenshot because the code embed wasnt working):

Where are you storing the humanoids that have already been damaged?

Also, are you disconnecting the RBXConnection after use is finished?

Humanoids are stored to a hitlist and the module auto checks if its already there.

As for .Touched, would I need to assign it to a variable to disconnect it or could I just write:

explosionHitbox.Touched:Disconnect()

Have you tried printing the hit list to see if it follows the logic?

Assign it to a variable.

Not your fault at all, but I think a lot of people don’t know how to disconnect connections and avoid memory leaks. There really should be some sort of PSA on this.

local connection = RandomService.DidSomething:Connect()
connection:Disconnect()

I have, it prints twice showing that .Touched is being activated twice

I’ve connected a variable to the event, but now my npcs dont get damaged and the hitbox doesn’t despawn.

							elseif ChosenCard.Name == "Explosive" then
								local explosionConnection: RBXScriptConnection
								local explosionHitbox = HitboxModule.CreateHitbox()
								explosionHitbox.Shape = Enum.PartType.Ball
								explosionHitbox.Size = 16
								explosionHitbox.DetectionMode = "Default"
								explosionHitbox.CFrame = hit.CFrame
								explosionHitbox.Visualizer = true
								explosionHitbox.VisualizerColor = Color3.new(1, 0.556863, 0.0470588)
								
								explosionConnection = explosionHitbox.Touched:Connect(function(explosionTouch, noid)
									for _, humanoid in ipairs(explosionHitbox.HitList) do
										if humanoid:IsA("Humanoid") then
											if humanoid.Parent == player.Character then continue end
											humanoid:TakeDamage(25)
										end
									end
									
									explosionConnection:Disconnect()
								end)
								
								explosionHitbox:Start()
								ChosenCard:Destroy()
							end

Well, this may be an issue with the module you are using. My only advice is to add a ton of print statements. Where does the code stop running? What does explosionHitbox.HitList equal? Does the touch connection run in the first place?

Also, for this type of connection you can actually use a helpful thing called :Once(). Just replace :Connect() with :Once() and it will only run, you guessed it, once.


Stuff to ignore

Oh wait, just realized, you’re trying to detect a humanoid which isn’t a real object. You can’t touch a humanoid. Look instead for:

										if humanoid.Name and humanoid.Name == "HumanoidRootPart" then
											if humanoid.Parent == player.Character then continue end
											humanoid.Parent:FindFirstChild("Humanoid"):TakeDamage(25)
										end

And why do you want to continue if it is part of the character? Continue exits the current iteration of the loop and goes to the next index. Do:

if humanoid.Parent ~= player.Character then continue end

Sorry for so many edits but I guess your module detects humanoids as objects which can be hit? In that case I have no idea why the code wouldn’t work.

With the hit list, it automatically finds the humanoid in whatever’s hit, so hit list is just a list full of humanoids. Touch does run as the code as previously (before I made the connection change), the humanoid would take damage, but it would do so twice. I had a print statement for the hit list set up which printed twice each time, which is how I noticed that touched fired twice. I will try :Once()!

Just noticed an issue with :Once(). The first time I throw a card out, it deals damage. But any time after that doesn’t damage since it’s disconnected

i’m just gonna rewrite this :sob: this is getting out of control

I couldn’t understand what you truly want to do. Did you try debounce?

I have tried debounce, but I’m trying it again

Do you want to damage all humanoids in the hitbox when the card is played?
If so, why are you using touched event? It seems better to just use function() without Connect()

.Touched is the function MuchachoHitbox uses for collision detection. I don’t know if that event uses the roblox .Touched, but thats how you’re meant to register touched objects

Why not just use :GetPartsInPart() for the hitbox? Then just get the humanoids in that explosion hitbox.

Could try that, but I don’t know if MuchachoHitbox uses parts. I think it uses the Spatial Query API

its likely cause your hitbox module handles the hits… no one makes hitbox module for it just to be a part that spawns, cause then it doesnt make sense why Start exists.

Hitbox:Start() likely returns array of hits it detected, idk why u are also detecting them urself

Then why the hell are u detecting the hits yourself? You just said the MuchachoHitbox already does it???
Do you even think before using an open module???

ok so i looked up at the module, and u are using it incorrectly, the Touched gives you hit and humanoid, you looping trough the HitList is what makes it damage multiple times, go check docs or a tutorial