Having trouble with a kills tracker

Hi!

I am making a PVP game with a kills and deaths tracker. I have edited the Roblox weapons kit, and it has been working well.
Everything is working fine, apart from the fact that if a player blows themselves up then it counts as a kill and a death. I just want it to count as a death. I was expecting my code to work, I don’t really know what I’ve done wrong.

	Player.CharacterAdded:Connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")

		humanoid.Died:Connect(function(died)
			Deaths.Value += 1
			local tag = humanoid:FindFirstChild("creator")
			local killer = tag.Value
			
			--[[ i have been using these to check values..
			
			print("The value of killer is:", killer)
			print("The value of humanoid.parent.name is:", humanoid.Parent.Name)
			print("is killer == humanoid?:", killer == humanoid.Parent.Name) -- **this keeps printing as false? even though it is the same?**
			print("tag:",tag)

			--]]
			
			if tag and killer then

				if killer == humanoid.Parent.Name then
					print(killer, "gets no kill points")
					
				else
					killer.leaderstats:FindFirstChild("Kills").Value +=1
					print(killer, "killed", humanoid.Parent.Name)
				end
				
			end
		end)

Thank you so much! Any help is appreciated!

1 Like

It depends on how your tags are formatted. What type of ValueBase is tag? Is it a ObjectValue or StringValue? If tag is a ObjectValue then your if killer == humanoid.Parent.Name then needs to be if killer == humanoid.Parent then but that could potentially lead to issues since humanoid.Parent will end up nil since the player is dying. Depending on what type of ValueBase tag is, we can come up with a better post-kill check.

Hi, thank you so much!

The tag is an ObjectValue, I’ll try with the if killer == humanoid.Parent then and see if there is any issues. EDIT: yup, still doesn’t work. I’ve done a bit of research into some other possibilities, and if killer.Name == humanoid.Parent.Name then seems to work, but I’m not sure if that is an ideal way to do it or not.

If you’re using Roblox’s legacy tag system then the killer tag’s value is a reference to a player instance and the tagged humanoid’s parent is a character model.

You should get the killer’s character via killer.Character and then compare that with the humanoid’s parent instead.

Its a good thing killer is an ObjectValue, that will make things easier.

If the tag’s value is the player instance, you should be able to replace if killer == humanoid.Parent.Name then with if killer == Player .

If the tag’s value is the Character, then a different workaround will have to be made.