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

How to stop getting added kills when shooting dead enemy?

Asked by
Jec0be 11
3 years ago
Edited 3 years ago

I made a script for a gun I made but when the enemy is dead, I can still shoot the enemy and still get added to my kills leaderstats. What is the problem? Script below (Is a Server Script)

local deagle = script.Parent

deagle.Shoot.OnServerEvent:Connect(function(player,mousePos)
    local raycastParams = RaycastParams.new()
    raycastParams.FilterDescendantsInstances = {player.Character}
    raycastParams.FilterType = Enum.RaycastFilterType.Blacklist


    local raycastResult = workspace:Raycast(deagle.Handle.Position,(mousePos - deagle.Handle.Position)*2147000,raycastParams)

    deagle.Handle.GunShot:Play()
    if raycastResult then
        local hitPart = raycastResult.Instance
        local model = hitPart:FindFirstAncestorOfClass("Model")

        if model then
            if model:FindFirstChild("Humanoid").Health >= 0 then
                if model.Humanoid.Health <= 28 then
                    player.leaderstats.Kills.Value = player.leaderstats.Kills.Value + 1
                end
                model.Humanoid.Health -= 36 
            elseif model:FindFirstChild("Humanoid").Health <= 0 then

                --nothing

            end
        end
    end
end)

1 answer

Log in to vote
1
Answered by 3 years ago

You are saying that if the health is EQUAL TO or BIGGER THAN 0 then add points on line 17. 0 health means dead, and you are saying to add points even if the player is dead which you do not want. I think you meant if the health is just bigger than 0?

if model:FindFirstChild("Humanoid").Health > 0 then -- if its BIGGER than 0
    -- blah blah blah
end
Ad

Answer this question