So I have a tank that fires grenades, and I have the grenade damage based on the distance the explosion center is from a humanoid, but for some odd reason, the distance parameter of the Hit event returns distances that are greater than the blast radius of the explosion itself. I even got values that were twice as large as the blast radius of the explosion itself. Is there any reason for this? Please help.
Here's the main grenade code:
Grenade.Touched:connect(function(Obj) if (not Obj:IsDescendantOf(Char)) and (not grenadeHit) then grenadeHit = true expSound:Play() local Explosion = Instance.new("Explosion") Explosion.BlastPressure = grenadeExplosionPressure --This is 50000 Explosion.BlastRadius = grenadeExplosionRadius --This is 15 Explosion.DestroyJointRadiusPercent = (grenadeRangeBasedDamage and 0 or 1) --This is currently set to 0 Explosion.ExplosionType = Enum.ExplosionType.NoCraters Explosion.Position = Grenade.Position Explosion.Hit:connect(function(Obj, Dist) local hitHumanoid = ( Obj.Parent:IsA("Accoutrement") and findFirstClass(Obj.Parent.Parent, "Humanoid") or findFirstClass(Obj.Parent, "Humanoid") ) if hitHumanoid then createCreatorTag(hitHumanoid) if grenadeRangeBasedDamage then local distFactor = 1 - (Dist / grenadeExplosionRadius) local baseDamage = distFactor * grenadeDamage if Obj:FindFirstChild("damageMultiplier") then print(distFactor) --This prints negative numbers for some reason hitHumanoid:TakeDamage(baseDamage * Obj.damageMultiplier.Value) else if Obj.Name == "Torso" then hitHumanoid:TakeDamage(baseDamage) end end end end end) Explosion.Parent = workspace wait() Grenade:Destroy() end end)
Thanks!
Explosion.BlastRadius = grenadeExplosionRadius --This is 15 1 - (Dist / grenadeExplosionRadius)
Math if Dist was > 15 then negative number