How to make a custom player list

I tried using a youtube tutorial to make a custom player list but it was scaling all weirdly and so i want to try redoing it and scripting it again but I don’t know how. Can anyone help me script this bc idk how to do this kind of stuff

1 Like

Could you be more specific please?

1 Like

I’m also using a custom player list, and I’m too lazy to do all the UI scaling and positioning, so Instead, I am using a ‘UIGridLayout’ which does the positioning for me. I am using PlayerAdded and PlayerRemoving to add the player frame template and removing when the player leaves the game.

This is a little example of how I am handling the events.

Here is a helpful link for you to understand what PlayerAdded and PlayerRemoving does.
https://developer.roblox.com/en-us/api-reference/event/Players/PlayerAdded#:~:text=The%20PlayerAdded%20event%20fires%20when%20a%20player%20enters,like%20print%20a%20message%20every%20time%20a%20

Okay so like I want to make a custom player list but I dont know how to script it and I can probably make the UI but how would I script it and stuff thats whats confusing for me

Just use player added and player removed and then update a UI grid layout like @TheAxisCode showed.

Or if you wanted you could create your own UI which held the players names.

1 Like

You will first have to make a scrolling frame. Then insert a UIListLayout into the frame. Then you can make 1 textlabel that fits into it. Put the textlabel somewhere like replicated storage. Then just start scripting. You have to put a Local Script into the frame.

local players = game:GetService("Players")

local frame = script.Parent
local textLabel = game.ReplicatedStorage.TextLabel

local function onPlayerRemoving(player)
    local playerTextLabel = frame:FindFirstChild(player.Name)
    if playerTextLabel then
        playerTextLabel:Destroy()
    end
end

local function onPlayerAded(player)
    onPlayerRemoving(player)
    local newTextLabel = textLabel:Clone()
    newTextLabel.Visible - true
    newTextLabel.Name = player.Name
    newTextLabel.Text = player.Name
    newTextLabel.Parent = frame
end

players.PlayerAdded:Connect(onPlayerAdded)
players.PlayerRemoving:Connect(onPlayerRemoving)

btw the code is very siimlar to the one that @TheAxisCode showed

2 Likes

You can try making the script detect when you press tab check if it’s already on by using a boolean, and if it’s not active, then get every player from the player list, and then create a text box inside a ScrollingFrame for each player. (ListPlayers is a ScrollingFrame). After that, try to automatically set the position of each box by checking how many elements the ScrollingFrame already has, multiplying that by the height of each text box so it fits nicely, and setting it’s Y position based on that. Finally, when you press tab again, it should check if it’s already active, and if it is, remove every box inside the ScrollingFrame to avoid breaking things the next time the list is opened.

Here’s the hierarchy of everything I did (UICorner and ListTitle are not needed, I just did it for testing purposes):
hierarchy

Here’s what I added to ListScript which does what I just described:

local userinput = game:GetService("UserInputService")
local startergui = game:GetService("StarterGui")
local players = game:GetService("Players")
local listframe = script.Parent
local playerlist = listframe.ListPlayers

--default list disable, remove if you're already doing this
repeat
	local load = pcall(function()
		startergui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
	end)
	wait(0.2)
until load

local function makebox(name, current)
	local listed = Instance.new("TextLabel", playerlist)
	listed.Position = UDim2.new(0,0,0,current*50)
	listed.Name = name
	listed.Text = name
	
	--you can use your own values here
	listed.BackgroundColor3 = Color3.new(0.247059, 0.247059, 0.247059)
	listed.Size = UDim2.new(1,0,0,50)
	listed.TextSize = 35
	listed.TextColor3 = Color3.new(1,1,1)
end

local function reload() --this reloads the player list when called
	for _,v in pairs(playerlist:GetChildren()) do
		v:Destroy()
	end
	for _,v in pairs(players:GetChildren()) do
		makebox(v.Name, #playerlist:GetChildren())
	end
end

local isActive = false
userinput.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Tab then --will show/hide with tab
		if not isActive then
			reload() --updates on tab press
			isActive = true
			listframe.Visible = true
		else
			isActive = false
			listframe.Visible = false
		end
	end
end)

--updates on player join/leave
players.PlayerAdded:Connect(reload)
players.PlayerRemoving:Connect(reload)

When you’re done, you should end up with something like this:
Nx3kUGyOop

Hope this helped!

3 Likes

Okay thanks but I noticed how you mentioned that the player list only updates when you press tab is there a way to make it always update since I’m going to have it show by default

Edited it, should work on player join/leave now.

1 Like

I tried it and it the box was bigger than how I set it and it didn’t show my name until I pressed tab here’s the script:

local startergui = game:GetService("StarterGui")
local players = game:GetService("Players")
local listframe = script.Parent
local playerlist = listframe.ListPlayers

--default list disable, remove if you're already doing this
repeat
	local load = pcall(function()
		startergui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
	end)
	wait(0.2)
until load

local function makebox(name, current)
	local listed = Instance.new("TextLabel", playerlist)
	listed.Position = UDim2.new(0.032,0,0.013,current*50)
	listed.Name = name
	listed.Text = name

	--you can use your own values here
	listed.BackgroundColor3 = script.Parent.ListTitle.BackgroundColor3
	listed.Size = UDim2.new(0.929, 0, 0.065, 0)
	listed.TextScaled = true
	listed.TextColor3 = Color3.new(1, 1, 1)
	listed.Font = "Cartoon"
	local Corner = Instance.new("UICorner", listed)
end

local function reload() --this reloads the player list when called
	for _,v in pairs(playerlist:GetChildren()) do
		v:Destroy()
	end
	for _,v in pairs(players:GetChildren()) do
		makebox(v.Name, #playerlist:GetChildren())
	end
end

local isActive = false
userinput.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Tab then --will show/hide with tab
		if not isActive then
			reload() --updates on tab press
			isActive = true
			listframe.Visible = true
		else
			isActive = false
			listframe.Visible = false
		end
	end
end)

--updates on player join/leave
players.PlayerAdded:Connect(reload)
players.PlayerRemoving:Connect(reload)

Adding reload() at the end of the script should do it. Not sure what you’re trying to do with the sizes though, so not sure how I can help with that.

I think I can probably figure out the size if I need help with that ill let yk

Screen Shot 2021-04-25 at 4.20.50 PM
Okay so I set the size to be the same as the player list text but its bigger than I expected it to be is there something in the script that will fix that
its fine if not it doesn’t really matter too much to me

Try removing listed.TextScaled = true, see if it helps.

1 Like

That just changes the text size I think its because its in a scrolling frame so its bigger but idk how I would make it smaller