How would I get ta random players DisplayName?

Im just stuck, Im trying to make a random player textlable that says a random players displayname
I Dont really know how to get a random player, its beyond my lua skills

local Players = game.Players:GetChildren()
local RandomPlayer = Players[math.random(1, #Players)]

print(RandomPlayer.DisplayName)
2 Likes

I suggest using GetPlayers() instead of GetChildren() when working with players. This would ensure you getting only players and not other objects under that service.

1 Like

Ok, Thanks, but how would I get the most active player? (Person who ran the most.)

When a player joins, you can assign a variable to them, that tells you their time while in the game, and you can make a loop that makes their time go up.

local Players = game:GetService("Players")

local PlayerTimes = {}

Players.PlayerAdded:Connect(function(player)
	PlayerTimes[player.Name] = 0
	
	while task.wait(1) do
		PlayerTimes[player.Name] += 1
	end
end)