I am trying to create an explosive projectile, with its resulting explosion dealing a scripted amount of damage that is dependent on the distance a player is from the position of the explosion and the explosion’s radius.
The hierarchy of the Tool that will fire this projectile is as follows:
Most of the functionality of the Tool is handled by a ModuleScript stored in ServerStorage which the
RangedWeaponScriptin the Tool requires from. The
Projectilegets duplicated, parented into Workspace and the
StandardProjectileScript (Highlighted) within the cloned
Projectilewill be enabled to handle events when the flying
Projectilecomes into contact with something.
Everything works as intended for the flying
Projectile when it comes into contact with a surface with the
StandardProjectile code except for one phenomenon which I can’t understand at all.
Projectile comes into contact with anything and its
Explosive BoolValue is marked as True, the
Projectile is meant to create an explosion at the point of contact. The excerpt of the
StandardProjectile Script is as follows:
if (script.Parent.Explosive.Value) then --Explosion handler. local explosion = Instance.new("Explosion", workspace) explosion.BlastPressure = 0 explosion.DestroyJointRadiusPercent = 0 explosion.BlastRadius = 30 explosion.Position = collisionEffectBlock.Position explosion.Hit:Connect(function(partHit, distance) print(partHit) print(distance) end) local exSound = script.Parent.ExplosionSound:Clone() exSound.Parent = collisionEffectBlock exSound.PitchShift.Octave = .9 + .2 * math.random() exSound.Volume = exSound.StandardVolume.Value * script.Parent.ExplosionAttack.Value / 25 exSound:Play() end
The resulting Explosion works fine and all, being able to push away unanchored Parts if the BlastPressure is set to anything greater than 0 and breaking joints if DestroyJointRadiusPercent is set to anything greater than 0. The
ExSound plays too and the Explosion is positioned at the point of contact. However, no output seems to be printed out from
explosion.Hit() for some very strange reason, even if the Explosion has an effect on Parts and joints in the Workspace.
To make sure my code was implemented correctly, I created a new Part with a ClickDetector in it, along with a simple Script, a child of the Part and therefore a sibling of the ClickDetector, as follows:
script.Parent.ClickDetector.MouseClick:Connect(function() local explosion = Instance.new("Explosion", workspace) explosion.BlastPressure = 0 explosion.DestroyJointRadiusPercent = 0 explosion.BlastRadius = 30 explosion.Position = script.Parent.Position explosion.Hit:Connect(function(partHit, distance) print(partHit) print(distance) end) end)
Upon clicking the Part with the ClickDetector, an Explosion is created and strangely enough, the output prints out every Part caught in the Explosion’s BlastRadius along with how far the Part was from the Explosion.
I am here to ask why the
Explosion.Hit() event cannot be reproduced by my explosive projectile.