Awarding Kills Not Working

Hi developers:

I’m working on a game where a player has a certain amount of “Kills” in their leaderstats (shown in game). The leaderstats work fine, but for some reason when they kill another player, their “Kills” value doesn’t increase like the script tells it to. Here’s the code, located in a Script in ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = leaderstats
	
	player.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function()
			local tag = character.Humanoid:FindFirstChild("creator")
			if tag ~= nil then
				local player = tag.Value
				player.leaderstats.Kills.value = player.leaderstats.Kills.Value + 1
			end
		end)
	end)

Any ideas would help! Thanks!

I’ve seen this same script so many times. Did you get it from a tutorial? When did you create the “creator” value in the Humanoid?

Also change that code to

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = leaderstats
	
	plr.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function()
			local tag = character.Humanoid:FindFirstChild("creator")
			if tag ~= nil then
				local player = tag.Value
				player.leaderstats.Kills.value = player.leaderstats.Kills.Value + 1
			end
		end)
	end)

You could just do if tag then.

Don’t think they can. Because I think that only returns true when the value is true.

1 Like

Yes it would, it might even make the script work. :man_shrugging:

Well, idk when they create the “creator” value. They didn’t show any code of what the player kills with, so we don’t know if it’s even created.

1 Like

Thanks for your inputs, I used a combination of your solutions and it worked!
The code:

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = leaderstats
	
	plr.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function()
			local tag = character.Humanoid:FindFirstChild("creator")
			if tag then
				local player = tag.Value
				player.leaderstats.Kills.value = player.leaderstats.Kills.Value + 1
			end
		end)
	end)
1 Like

Nice! Please press the Solution button on this post that I’m replying to and also edit the post to provide the code for anyone else that is having this problem.

Have a good day!

All his script did was change the variable for player. I think mine was the one that solved the problem. His also helped by creating 2 different variables. You should have named the other player variable killer or something else.

1 Like

The creator value is something the roblox classic sword uses to detect kills. I think it was from a tutorial, because I have seen this many times to

1 Like