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.
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.
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.