pesde goatsoft / lucy

Avatar

A player's headshot in a circle. Bots and empty slots, which have no Roblox account, show the first letters of their name instead.

Avatar exampleAvatar example
Lucy.Stack.new({
    direction = "horizontal",
    gap = "Space2",
    children = {
        Lucy.Avatar.new({ name = "DJ Lucy", size = "lg" }), -- no userId: shows DL
        Lucy.Avatar.new({ name = "Nova", size = "lg" }),
        Lucy.Avatar.new({ name = "Beatrix", size = "lg" }),
        Lucy.Avatar.new({ name = "Kai", size = "lg" }),
        Lucy.Avatar.new({ name = "Juno", size = "lg" }),
    },
    Parent = parent,
})

Props

PropTypeDefaultState keyWhat it does
userIdnumber0yesThe player's user ID. 0 or below shows the monogram
namestring""yesThe name the monogram's letters come from
sizestring or number"md"yessm (32 pixels), md (40), lg (56) or xl (80, a featured player: who is up next, a profile), or a number of pixels, such as 120 for the winner on a podium
visiblebooleantrueyesShows or hides it
squarebooleanfalseRounded corners instead of a circle
backgroundbooleantruefalse leaves nothing behind the face: only the picture, clipped to its shape

It also takes the props every component takes.

The monogram is the first letter of each of the first two words in name: "DJ God" shows DG, "Moonwalker" shows M, and no name shows ?.

Its parts are on the handle: avatar.image is the headshot and avatar.monogram the letters. Lucy.Avatar.headshot(userId) gives the headshot URL on its own, and Lucy.Avatar.initials(name) the letters.

Examples

A Top Dancers slot that changes as players and bots come and go:

local slot = app.state:ref("topDancers.1") -- { userId = number, name = string }

Lucy.Avatar.new({
    userId = function() return slot().userId end,
    name = function() return slot().name end,
    size = "lg",
    Parent = podium,
})

In a row of the Crew list:

Avatar exampleAvatar example
Lucy.Item.new({
    title = friend.DisplayName,
    description = `@{friend.Name}`,
    media = Lucy.Avatar.new({ userId = friend.UserId, name = friend.DisplayName }),
    Parent = crewList,
})

The winners on a podium: big square faces with nothing behind them, each headshot clipped to its corners:

Avatar exampleAvatar example
Lucy.Stack.new({
    direction = "horizontal",
    gap = "Space4",
    align = "end",
    children = {
        Lucy.Avatar.new({ userId = 156, name = "Nova", size = 96, square = true, background = false }),
        Lucy.Avatar.new({ userId = 1, name = "Kai", size = 128, square = true, background = false }),
        Lucy.Avatar.new({ userId = 261, name = "Juno", size = 84, square = true, background = false }),
    },
    Parent = parent,
})

Preview

In Studio, from the command bar: Lucy.Preview.show("Avatar").