Player wont get +1 kill in leaderstats

For some reason, when you kill another player, it just wont add +1 kill to the leaderstats. Any help?

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		player.Character.Humanoid.Died:Connect(function()
			local humanoid = player.Character:WaitForChild("Humanoid")
			local tag = humanoid:FindFirstChild("creator")
			if tag and tag.Value then
				local playername = tag.Value
				local killer = game:GetService("Players"):FindFirstChild(playername.Name)
				killer.leaderstats.Kills.Value += 1
			end
		end)
	end)
end)
2 Likes

What have you done to debug this code? It also seems as if the “creator” instance is an ObjectValue, which suggests it holds a Player instance. If this is the case, why are you deriving them again by searching for them under the Players service via Instance:FindFirstChild?

(If you find that there is no value tied to the ObjectValue, then your weapons are at fault)

4 Likes

Ensure you check the killer exists using FindFirstChild so that you can also check their leaderstats then award them

1 Like

Also, it may be an issue with your weapon not tagging a player with an object value

To be honest he still gets the player object but makes it one line of code longer

Ohh wait sorry, I misunderstood the code lol.

Mayb ‘kills’ doesn’t exist yet: killer.leaderstats.Kills.Value += 1. Try: killer.leaderstats:WaitForChild("Kills").Value += 1

I think he isnt being very clear on how all the code works he is only portraying one script than the scripts that actually link together such as him coding the leaderstats script and the tool or tools that create the object value

1 Like

Try this code if it doesnt help then other code or scripts are affecting this script:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Char)
        local humanoid = Char:WaitForChild("Humanoid")
		humanoid.Died:Connect(function()
			local tag = humanoid:FindFirstChild("creator")
			if tag and tag.Value then
				local killer = tag.Value
				local leaderstats=killer:FindFirstChild("leaderstats")
                if leaderstats and leaderstats:FindFirstChild("Kills") then

				     leaderstats.Kills.Value += 1
                end
			end
		end)
	end)
end)

[/quote]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.