Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to take a headshot of a random player and put it on a ImageLabel?

Asked by 4 years ago
Edited 4 years ago

I am working on a story game and i need a random players headshot and put it on an ImageLabel.

--// Variables
local players = game.Players:GetChildren() 
local randomplayerid = players[math.random(1,#players)].PlayerId
local thumbSize = Enum.ThumbnailSize.Size420x420
local thumbType = Enum.ThumbnailType.HeadShot
local imageLabel = script.Parent

--// making the headshot of the player
local content, isReady = players:GetUserThumbnailAsync(randomplayerid, thumbType, thumbSize)
--// adding the headshot image on the ImageLabel
imageLabel.Image = content

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

There are a few instances I would change in your code.

You used players to get the children of the player's service rather then service itself, so it would error when use it in line 9. Furthermore, PlayerId should be UserId. I would personally declare your variables a bit more organised, so it's a bit more clear.

-- Variables
local players = game.Players:GetPlayers() 
local randomPlayer = Players[math.random(1, #Players)]
local userId = randomPlayer.UserId

local thumbSize = Enum.ThumbnailSize.Size420x420
local thumbType = Enum.ThumbnailType.HeadShot
--// making the headshot of the player
local content, isReady = game:GetService("Players"):GetUserThumbnailAsync(userId, thumbType, thumbSize)

local imageLabel = script.Parent
--// adding the headshot image on the ImageLabel
imageLabel.Image = content
Ad

Answer this question