Explosion.Hit event does not fire

For some reason, Explosion.Hit event is not working. This was working at one point then stopped. The problem occurs in both Studio and the live server. I have also read Roblox’s API documents and I don’t see any problems with my code. It just seems that the event does not fire at all since the print statements are not being executed. The explosions, however, works fine.

Here is a video showing the problem. WARNING Turn down your volume. It’s LOUD.

https://vimeo.com/747498100

Here’s the code in question:

Grenade Projectile Script

-- Explosion hit logic.
hitConnect = explosion.Hit:Connect(function(hit, distance)
	print("Explosion Hit", hit, distance)
	local params = {
		blastPos = explosion.Position;
		radius = projEffects.explosion.radius;
		distance = distance;
	}
	weaponsMod.processHitAoE(player, hit, playerTable, params, toolData, toolInstance)
end)

Rocket Projectile Script

-- Explosion hit logic.
hitConnect = explosion.Hit:Connect(function(hit, distance)
	print("Explosion Hit", hit, distance)
	local vector = (hit.Position - explosion.Position)
	local params = {
		position = explosion.Position;
		radius = projEffects.explosion.radius;
		vector = vector;
		distance = distance;
	}
	weaponsMod.processHitAoE(player, hit, playerTable, params, toolData, toolInstance)
end)

I have also read the following articles here on the developer forums:

https://devforum.roblox.com/t/explosionhit-not-producing-any-output/636229
https://devforum.roblox.com/t/why-doesnt-explosion-work/1641698
https://devforum.roblox.com/t/explosion-hit-isnt-working/1903882

The second article mentions that Explosion.Hit will not fire if the hit part is not a descendant of a humanoid model. However, as you can see in the video. I’m hitting a humanoid (an NPC to be specific), and then I went and stepped on a grenade to set it off.

Any ideas as to why this isn’t working?

1 Like

Maybe it is on Line 3 because ROBLOX Tells me this

image

Are you sure the connection is being reached (nothing is yielding the script)? If you are, what are the values of CanCollide, CanQuery, and CanTouch in your NPC?

Yes. The connection is being reached. I added a print statement at the end of the projectile script. When the script is cloned and enabled, I get connections on all three events that I’m watching.

The NPC has on the HumanoidRootPart CanCollide = true and CanTouch = true.

I probably should have mentioned (you can see it in the video) that it doesn’t work for players either. I stepped on the grenade which causes it to explode immediately and I received no damage and there was no printout.

At this point, your guess is as good as mine.

Umm… Line 3 you say? The print statement? Or did you mean line 2?

In either case, the event is not being fired. “hit” is the part that got hit. “distance” is self-explanatory. This matches the prototype that you posted. This one is a real head scratcher because everything is setup correctly as far as I can tell.

probably isn’t the issue, but it’s worth a shot:

what happens if you remove the hitConnect = bit?

Also, how are you defining / creating explosion

Removing hitconnect doesnt do anything exeptdisconnecting the event.

Like this:

local explosion

-- Create Explosion
local function createExplosion()
	local data = projEffects.explosion
	explosion = Instance.new("Explosion")
	explosion.BlastPressure = data.pressure;
	explosion.BlastRadius = data.radius
	explosion.ExplosionType = data.btype
end

-- Explode
local function explode()
	armed = false
	local position = projectile.PrimaryPart.CFrame
	explosion.Position = (position *
		CFrame.new(projEffects.explosion.offset)).Position
	explosion.Parent = game.Workspace

	-- We reparent the script to the tool instance
	-- so it will continue to execute when the
	-- projectile is destroyed.
	debrisService:AddItem(script, 5)
	script.Parent = toolInstance
	projectile:Destroy()
end

That second function is called when the projectile explodes. The second part I have because the projectile is destroyed but the script needs to stay running a bit longer. This code was modeled after Roblox’s standard rocket launcher.

I have a different type of rocket launcher that fires rockets armed with tactical nuclear warheads. That one works properly, but the mechanism that it operates on is also different.

So nobody has any idea what the issue is or how I can fix it?

I figured it out. In the projectile script, when the projectile was being destroyed, all of the event handlers were being disconnected. It should have been when the script was destroyed instead. I made changes to it and it’s now working.