My points and kills won't go up when a player kills another player

Ok I tried to make a leaderboard. The points and kills properly shows up, but when you kill someone, your points and kills won’t go up.

game.Players.PlayerAdded:Connect(function(plr)
 

 local stats = Instance.new("Folder")
 stats.Name = "leaderstats"
 stats.Parent = plr
 
 local kills = Instance.new("IntValue")
 kills.Name = "Kills"
 kills.Parent = stats
 
 local Points = Instance.new("IntValue")
 Points.Name = "Points"
 Points.Parent = stats
 
 plr.CharacterAdded:connect(function(char)
  
  local humanoid
  
  repeat
   humanoid = char:FindFirstChild("Humanoid")
   wait()
  until humanoid
  

   
   local tag = humanoid:FindFirstChild("creator")
   
   if tag then
    
    local killer = tag.Value
    
    if killer then
     
     killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
     killer.leaderstats.Points.Value = killer.leaderstats.Points.Value + 5
    end
    end 
     

     end)
 
     
      end)
1 Like

You should place the code that looks for the killer inside a Humanoid.Died event:

plr.CharacterAdded:connect(function(char)
	local humanoid = char:WaitForChild("Humanoid") -- Script yields until the humanoid is found
	humanoid.Died:Connect(function() -- Execute upon humanoid entering Dead state.
		local tag = humanoid:FindFirstChild("creator") -- Look for killer tag, assuming object class is ObjectValue
		if tag then
			local killer = tag.Value -- Look for killer (assuming in Players service)
			if killer then -- Increase values below:
				killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
				killer.leaderstats.Points.Value = killer.leaderstats.Points.Value + 5
			end
		end
	end)
end)
4 Likes