Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to stop getting added kills when shooting dead enemy?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.