How Do I Make a Player Profile Picture and Username?

I want to make a system that will display the player’s profile picture and username on a Billboard GUI when they press a brick. However, this isn’t working. Are there any errors in my script?

local brick = script.Parent.Parent.Parent
local picture = script.Parent.ImageLabel
local user = script.Parent.TextLabel

function onTouch (Object)
	local Character = Object.Parent:FindFirstChild("Humanoid")
	local Player = game.Players:GetPlayerFromCharacter(Object.Parent)
	if (Character ~= nil) then
		if (Player ~= nil) then
			local Player = game.Players:GetPlayerFromCharacter(Object.Parent)
			picture.Image = "http" .. Player.Name
			user.Text = Player.Name
		end
	end
end
script.Parent.Touched:connect(onTouch())

profile.rbxl (27.6 KB)
Here is the file if you need it.

3 Likes

You are instantly calling onTouch instead of connecting the function

Remove the extra ()

- script.Parent.Touched:connect(onTouch())
+ script.Parent.Touched:connect(onTouch)
1 Like

Okay thank you I will try that. It still does not work though.

1 Like

Do you want it to happen when you press(click) on the brick or touch the brick? Not sure because in description you said press yet your code means touched.

Un-necessary question but what book were you referring to?

It is called “Intermediate Roblox Programming”

1 Like

I just noticed even though it works it would spam “Attempted to index nil” when trying to get playerId or something like that, so the final version without that alert:

local brick = script.Parent.Parent.Parent
local picture = script.Parent.ImageLabel
local user = script.Parent.TextLabel
local Players = game:GetService("Players")

function onTouch (Object)
	local Character = Object.Parent:FindFirstChild("Humanoid")
	local Player = game.Players:GetPlayerFromCharacter(Object.Parent)
	if Player ~= nil then
		local userId = Player.UserId
		local thumbType = Enum.ThumbnailType.HeadShot
		local thumbSize = Enum.ThumbnailSize.Size420x420
		local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
		if (Character ~= nil) then
			picture.Image = content
			user.Text = Player.Name
		end
	end
end
brick.Touched:connect(onTouch)

Let me know if you want to know how it works or don’t understand something.

2 Likes