Random Player Picker GUI

Quick Intro: Hey Devs! Some of you may remember me on the DevForum a couple years ago. Well, after a long absence (3 years,) I am back!

I was wondering how to create a GUI that randomly picks a player for my new game, similar to that of the one in Hide and Go Seek Extreme, where it displays a player’s avatar and username while flipping through each player in the server.

Thank you!!

2 Likes

You can try the search bar next time before creating a new post.

1 Like

I already know how to make a random player picker, but I’m not sure how to turn it into a GUI.

1 Like

You can place the random player in a variable to get their name and profile picture.

1 Like

The GUI would loop through all players’ names and avatars, like the one in Hide and Go Seek Extreme.

1 Like

You can try a for loop?

1 Like

you can use for i, player in pairs(Players:GetChildren() do to loop through all players.

if you want to get just a image of the player’s avatar you can use :GetUserThumbnailAsync, or you can use viewportframes if you want to get all the player avatar or from a custom angle and camera.

local function pickRandomValue(arr: {}): any
	return #arr > 0 and arr[math.random(#arr)] or nil
end

local function pickRandomPlayer(): Player?
	local players = game.Players:GetPlayers()
	return pickRandomValue(players)
end
1 Like
local Players = game:GetService("Players")

local noIconFound = "rbxassetid://0" -- Put any image you want to show if you can't get the player's Icon

local function GetPlayerIcon(Player : Player)
    local userId = player.UserId
    local thumbType = Enum.ThumbnailType.HeadShot
    local thumbSize = Enum.ThumbnailSize.Size420x420
    local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
    return (isReady and content) or PLACEHOLDER_IMAGE
end

local function pickRandomPlayer()
    local PlayerList = Players:GetPlayers()
    local RandomNumber = math.random(1, PlayerList)
    local selectedPlayer = PlayerList[RandomNumber]
    print(`Selected a Player: ${selectedPlayer}`)
    local plrIcon = GetPlayerIcon(selectedPlayer)
    --Set the ImageLabel on the GUI to plrIcon
end

This should do what you’re hoping for. The only thing it isn’t doing is the flipping through the players. It just picks a random player and get the headshot of the picked player.

GetPlayerIcon() is taken right from Roblox’s Documentation

Players | Documentation - GetUSerThumbnailAsync

If you want help with making the flipper just let me know, and I’ll guide you towards the right direction.