Bullets are creating explosions twice when hitting multiple parts?
Asked by
8 years ago Edited 8 years ago
I'm pretty confused on the workaround for this. My gun's bullets, when hitting multiple parts, runs the touched event twice before the bullet is destroyed.
01 | missile.Touched:connect( function (hit) |
02 | if hit.CanCollide ~ = false or hit.Name = = "Right Leg" or hit.Name = = "Left Leg" or hit.Name = = "Left Arm" or hit.Name = = "Right Arm" then |
03 | if hit.Transparency ~ = 1 then |
05 | local E = Instance.new( "Explosion" ) |
06 | E.BlastPressure = S.ExplosionPressure |
07 | E.BlastRadius = S.ExplosionRadius |
08 | E.DestroyJointRadiusPercent = (S.RangeBasedDamage and 0 or 1 ) |
09 | E.ExplosionType = S.ExplosionType |
10 | E.Position = missile.Position |
11 | E.Parent = game.Workspace |
12 | E.Hit:connect( function (hitPart, partDistance) |
13 | if ( not hitPart:IsDescendantOf(Character)) and hitPart.Name = = "Torso" then |
14 | print ( "Hit " ..hitPart.Name.. "!" ) |
15 | local humanoid = hitPart.Parent:FindFirstChild( "Humanoid" ) |
17 | local distance_factor = partDistance / E.BlastRadius |
18 | local distinvert = 1 - distance_factor |
19 | local newdamage = damage*distinvert |
20 | humanoid:TakeDamage(newdamage) |
So, due to this, it creates two explosions, thus harming any humanoids nearby twice. How would I prevent this from happening?