Updating Players Kills

Hello,

I have been trying to write a script that updates a players kills in their leaderstats but it won’t. The Output keeps saying Kills is nil~, Please take a look and help because I’m sure it’s an easy mistake.

Players = game:GetService(“Players”)
Players.PlayerAdded:connect(function(Player)

Player.CharacterAdded:connect(function(Character)
local Humanoid = Character:WaitForChild(“Humanoid”)
Humanoid.Died:connect(function()
if Humanoid:FindFirstChild(“creator”) ~= nil then
local Killer = Humanoid.creator.Value

  		game.Players.Killer.leaderstats.Kills.Value = game.Players.Killer.leaderstats.Kills.Value + 1
  		
  		
  	end 
  	
  end)

end)
end)

Thank you!

1 Like

It is because you are referring to the player as game.Players.Killer but instead you should be using game.Players[Killer]

But…

If Killer is equal to the player itself, you just need to use Killer, without using game.Players. But if Killer is a StringValue, use what I said above.

So should it look like game.Players[Killer].leaderstats.Kills. etc…?

What exactly is Killer equal to? The player’s name or the player instance?

It’s equal to the Killers name. Such as if I would do print(Killer) it would print the Killers name.

Make sure that it is, because even if you were to print a player’s instance, it will print their name.

After making sure, do the following

If you confirmed that Killer is equal to the NAME of the player…
Replace the line with this:

game.Players[Killer].leaderstats.Kills.Value += 1

If Killer is equal to the INSTANCE of the player…
Replace the line with this:

Killer.leaderstats.Kills.Value += 1