World/MainMenuText.cs

A game Component that populates a TextRenderer on start with a welcome message and player level/stats. It reads the local connection, local player stats, and the current local level to build strings and sets TextRenderer.Text.

🐞 PlayerStats is never used and the final TextRenderer.Text only contains PlayerWelcome, so kills/deaths are never displayed.
using KOTH.PlayerExp;
using Sandbox;
using Sandbox.Diagnostics;

namespace KOTH;

public sealed class MainMenuText : Component
{
	[RequireComponent] public TextRenderer TextRenderer { get; set; }

	protected override void OnStart()
	{
		base.OnStart();

		Assert.NotNull(Connection.Local);

		TextRenderer.Text = "";

		var LocalStats = PlayerState.Local.LocalStats;

		var LocalPlayerLevelObject = ExpManager.GetCurrentLocalLevel();
		var PlayerWelcome = $"welcome {Connection.Local.DisplayName}\nLevel {LocalPlayerLevelObject.LastValue}";
		var PlayerStats = $"kills {LocalStats.KillsStat.Value} : Deaths {LocalStats.KillsStat.Value}";

		TextRenderer.Text = $"{PlayerWelcome}\n";
	}
}