Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Damage being reverted by gun randomly?

Asked by 7 years ago

In the LocalScript of my gun, the hit detection of the bullet is the following code:

    missile.Touched:connect(function(hit)
        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
            if hit.Transparency ~= 1 then -- The above could lag?
                local E = Instance.new("Explosion")
                E.BlastPressure = S.ExplosionPressure
                E.BlastRadius = S.ExplosionRadius
                E.DestroyJointRadiusPercent = (S.RangeBasedDamage and 0 or 1)
                E.ExplosionType = S.ExplosionType
                E.Position = missile.Position
                E.Parent = game.Workspace
                    E.Hit:connect(function(hitPart, partDistance)
                    if (not hitPart:IsDescendantOf(Character)) then
                        local humanoid = hitPart.Parent and                       hitPart.Parent:FindFirstChild("Humanoid")
                        if humanoid then
                            if humanoid.Name ~= script.Parent.Parent.Name then
                                        local distance_factor = partDistance / E.BlastRadius
                                        distance_factor = 1 - distance_factor                       
                                        humanoid:TakeDamage(damage*distance_factor)
                            end               
                        end
                    end
                end) 


                --HitSound:Play()
                missile.Parent = nil
            end
        end
    end)

For some reason, at random, the bullet's damage will be reverted. For example, I'll shoot someone. Deals damage like normal. Shoot again, and for a split second, it looks like i've damaged them (health bar), but then reverts back to the health they had before.

Any ideas? Thanks!

0
Lag Confirmed :) Is this happens even when you try it on local test mode with random dummies? superalp1111 662 — 7y
0
Are you sure you don't have a conflicting script? User#13152 0 — 7y
0
Would you consider health regeneration a conflicting script? And no, it doesn't happen when I test it locally. Lag could be an issue, as when I test it locally I see my bullets lagging a lot, but when I play via server, they look fine. coolyoshipower 42 — 7y

Answer this question