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
4 years ago
Edited 4 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)

01local deagle = script.Parent
02 
03deagle.Shoot.OnServerEvent:Connect(function(player,mousePos)
04    local raycastParams = RaycastParams.new()
05    raycastParams.FilterDescendantsInstances = {player.Character}
06    raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
07 
08 
09    local raycastResult = workspace:Raycast(deagle.Handle.Position,(mousePos - deagle.Handle.Position)*2147000,raycastParams)
10 
11    deagle.Handle.GunShot:Play()
12    if raycastResult then
13        local hitPart = raycastResult.Instance
14        local model = hitPart:FindFirstAncestorOfClass("Model")
15 
View all 29 lines...

1 answer

Log in to vote
1
Answered by 4 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?

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

Answer this question