Kill counter increases whenever you shoot a dead player more

I’m trying to make a kill counter that detects when you kill someone with your gun (obviously) and it works great except for the fact that if you shoot any of the pieces of the dead player, you’ll get extra kills credited to you. Any way to fix this?

local model = hitPart:FindFirstAncestorOfClass("Model")
		local name = model
		
		
		if model then
			if model:FindFirstChild("Humanoid") then
				model.Humanoid.Health -= 30
				if model.Humanoid.Health <= 0 then
					kills.Value = kills.Value + 1
2 Likes

Use the Humanoid.Died event so that it only fires once when you wanna increase the kills.Value

You could do a check that is 10x easier

local model = hitPart.Parent
if not model:findFirstChild("Humanoid") then return end
model.Humanoid:TakeDamage(30)
if model.Humanoid.Health <= 0 then
kills.Value = kills.Value + 1

But this one will bug doe to,
You can shoot the humanoid now 30 times whilst its dead and that will basically ruin the kills.

Best way would be to add a “Tag” inside the Humanoid, and put inside the plrscharacter a script to check if Humanoid died and if Humanoid finds a Tag,

Tag = A ObjectValue

Tag.Value.Kills.Value=Tag.Value.Kills.Value+1

In total:
grafik

local humanoid = script.Parent.Humanoid

humanoid.Died:connect(function()
	if humanoid:findFirstChild("Tag") then
		local tag = humanoid.Tag
		local plr = tag.Value -- the plr he got killed by
		-- ur thing here
	end
end)

Your damage script

local a = game.Players.LocalPlayer--for test


local model = hitPart.Parent
local humanoid = model:findFirstChild("Humanoid")
if not humanoid then return end
humanoid:TakeDamage(30)

if humanoid:findFirstChild("Tag") then
	humanoid.Tag.Value = a--plr he got hit by
else
local tag = Instance.new("ObjectValue",humanoid) tag.Name = "Tag" tag.Value = a--plr he got hit by
end

If you wanted to keep it simple you could have 2 if statements for testing the current health of the player to deal damage, and then award a kill.

if humanoid.Health > 0 then
--//It's alive, deal damage
humanoid:TakeDamage(30)

if humanoid.Health <= 0 then
--//Humanoid has died, award kill
kills.Value += 1
end
end
3 Likes

Sorry for the late reply and I hope you’re still there but where exactly am I supposed to increase the value in any of those scripts?

my friend said humanoid.Died doesnt fire when the value is under 0, so here

humanoid:GetPropertyChangedSignal('Health'):Connect(function()
  local new = humanoid.Health
  if new <= 0 then
   value += 1
  end
end)

I am not sure where you are confused at, but u gotta set the plr who fired inside the local a thingy.

Basically there’s nothing that increases the kill value in either of those scripts and I’m wondering where I’d put it

the --ur thing here?
That’s where ur thing has to be.

alright thanks I’ll try it now

Again, a ridiculously late response but now the output says there is a parenthesis that wasn’t closed but I can’t tell where. It probably in this script since my script didn’t have any unclosed parenthesis problems. But anyways, I can’t tell where your script’s unclosed parenthesis is

local a = game.Players.LocalPlayer–for test

-- Can't find the unclosed parenthesis
local model = hitPart.Parent
local humanoid = model:findFirstChild("Humanoid")
if not humanoid then return end
humanoid:TakeDamage(30)

if humanoid:findFirstChild("Tag") then
	humanoid.Tag.Value = a--plr he got hit by
else
local tag = Instance.new("ObjectValue",humanoid) tag.Name = "Tag" tag.Value = a--plr he got hit by
end

hmm pls add me on discord Spy#0005

Very efficient script!, in my opinion this script is better

1 Like