Custom Icon for Playerlist

Is there a way to be able to have a custom icon on your username in the Playerlist in your own game? A tutorial would be nice. Thanks!

  • Virtual_Sunset
8 Likes

You probably have to make a custom player list to achieve something like this.

1 Like

Do you know where I could possibly find a tutorial on that?

1 Like

I could help you with that if you want.

1 Like

I would really love some help on that. As I am trying to learn RLUA but it’s really hard for me to grasp how to do it. Reach me on Discord as I will be most active on there. The Developer#0001 Thanks!

1 Like

Its easier for me if I show you here. So uh V

First you’d want to make a Screen Gui and inside of it a Scrolling Frame and a UiListLayout.

11%20AM

Also a template for what you want the names to look like.

Then you want to make a local script where it would it would update the list when someone joins and leaves as well as when you first join.


function update()
for i,v in pairs (game.Players:GetChildren()) do
local new = script.Parent.Template:Clone()
new.Parent = script.Parent.ScrollingFrame
new.Text = v.Name
new.Visible = true
end
end

game.Players.PlayerAdded:Connect(function(plr)
update()	
end)

game.Players.PlayerRemoving:Connect(function(plr)
update()	
end)

update()

It’s as simple as that up until you want to add more features to it. I could help you with icons if you need.

https://gyazo.com/ff369e9a918d86413375dcddf5c90d59

Tell me if you have any questions :face_with_raised_eyebrow:

6 Likes

You can’t add a custom icon to the leaderboard unless you create a custom leaderboard. I’m also not really giddy about providing code without you first attempting this problem yourself, but you say that you’re learning (which is a good thing!), so I can provide you a tutorial with some further reading. I will only teach you how to make a primitive leaderboard; any further functionality is up to you to explore.


The first thing you’re going to want to look at are GuiObjects since these are what you need for Guis. All your Gui elements are going to be contained inside a LayerCollector - for this case, you’re going to be using a ScreenGui as your LayerCollector. Put this in StarterGui and ensure the ResetOnSpawn property is false - it’s useless to have the Gui reset when a player respawns, when you can have the logic run once and help yourself out a ton.

Next thing you want is a way to make a list at all, given this is a player list. This all depends on your application of the aforementioned GuiObjects. Like in @JelIybeIly’s post, you can use a ScrollingFrame to start. Once you have this in and you’ve tweaked the properties the way you wanted, you should end up with a fairly rudimentary interface.

Note: make sure to use scalar properties when making your interfaces. Using offset only usually preserves the kind of Gui you want, but it does not scale on other platforms or screen types. They are the first number in the pair of Size/Position properties formatted as {0, 0}, {0, 0}.

image

Next thing is getting the logic down. Stick a UIListLayout object in your ScrollingFrame. The UIListLayout object will pass the work of displaying your elements to the Gui engine, so you don’t have to do any real scripting to format the list on your own. Your only need is to get the frame filled with elements.

image

Now, the scripting part. Again; this is just a primitive leaderboard, so it’ll display players in the order that they join in (or whatever you selected as the SortOrder for the UIListLayout object - could be alphabetical as well). First thing we need is a template. This object will get used for new entries in the Gui. Your template will need to be a Frame, so that you can have both a player name and icon. The Icon will be an ImageLabel and the player name will be in a TextLabel.

What it looks like raw:

What it’s like when it gets added:

Set the Frame’s visibility to false. You won’t need any players to see your template. Alternatively, you can keep it visible and instead let the script handle this end by keeping a clone as a variable or just setting it invisible like stated earlier.

Now, scripting. The probable finale. Because you are working with a Gui, you will need a LocalScript to go along with your Gui. Insert this under the ScreenGui, because it’s good for organisation and ease of access to the rest of your object hierarchy (Explorer).

For the LocalScript, it will handle the code part of your Gui. To make this work, you are going to need to know how to use some things. Those are:

Now, your code. I did say I won’t provide any snippets so you can learn, only a direction of where you should go. I will explain the steps in which you need to take:

  • Define your variables at the top of the script. You will need one for the Players service fetched from GetService, one for the Gui and one for the template. Depending on your style for the template, you can try one of three things:
-- 1: If it is visible
local Template = script.Parent:WaitForChild("Template")
Template.Visible = false

-- 2: If it is invisible
local Template = script.Parent:WaitForChild("Template")
Template.Visible = false

-- 3: If you're feeling adventurous
local Template = script.Parent:WaitForChild("Template"):Clone()
script.Parent.Template:Destroy()
  • A function that’ll help facilitate the initiation of the leaderboard. Players already in the server need to exist in your board. For this, you need to iterate (go through) a list of players using the GetPlayers function of the Players service.
local function AddPlayerToBoard(Player)
    -- if Player is a Player, then copy the template
    -- assign template properties like name and whatnot, put in ScrollingFrame
end

for _, Player in pairs(Players:GetPlayers()) do
    AddPlayerToBoard(Player)
end
  • Next, any player that joins needs to get added as well. Connect your function to the PlayerAdded event. Don’t worry about doing anything extra, the function will take care of it for you.
Players.PlayerAdded:Connect(AddPlayerToBoard)
  • And finally, every player who leaves needs to get chucked out. Connect a function to PlayerRemoving that will search the leaderboard for an element matching the player’s name, then remove it. This method will only work if your frames are the player’s names as well, not just the Text of the TextLabel.
Players.PlayerRemoving:Connect(function (Player)
    local PlayerSlot = ScrollingFrame:FindFirstChild(Player.Name) then
    if PlayerSlot then PlayerSlot:Destroy() end
end)

And then, once this is all done, you got yourself a leaderboard! Now, setting the icon, your original question. This… is all up to you! Go wild, do something!

local Icons = {
    ["Normal"] = "rbxassetid://someAssetNumber"
}

-- in the AddPlayerToBoard function (dont use verbatim, its an example)
NewSlot.Icon.Image = Icons["Normal"]

And now I’m exhausted. The curtain falls. My tutorial is finished. Leave questions if you wish for clarification, or a like if it was helpful. I’ve been running low on those these days.

50 Likes

I have a question! Is it possible to modify the default leaderstats core scripts? If so, how. I’m attempting to make a leaderboard similiar to this:

image

I have been scripting for quite a bit, but haven’t ever really messed with core scripts. I was hoping you could help!

It isn’t posible to modify ROBLOX core scripts. However, you can make your own leaderboard pretty easily with some simple events, server code and StarterGui:SetCore() for disabling the default leaderboard (hey razor lol)

Colbert has an extremely good explanation above for making your own.

1 Like