How to list these usernames on a UI (surface UI)

Hello everyone,

So I am trying to create this board where people can click on add to list and it will add them to a table. After the user who is first in the list leaves they get removed from the list and the next user gets put on. I am want to make it so you can see the upcoming members in a line at the side but I am unsure on how I could do this. By the way the list of the playes added will be used by a table as we don’t need to save the data just for that server.

(this is the basicly lay out of it but I will also want something saying the current first user as well)

image

3 Likes

how about you use the playerAdded function to add players to your table?

local myTable = {}
local i = 0
game.Players.PlayerAdded:connect(function(plr)
       table.insert(myTable, i + 1, plr.Name)
       
end)
--and add the table to board

That is not what I am asking for though. I know how the tables will work but I want to know how I can list them down the side on the UI player by player.

for more help visit this

there tons of tutorials related to this just search it up

That is not what I am asking for though… Please stop just making things up as it is not helping anyone. It is simple what I am asking and there are no tutorials for what I am looking to make or I would not create this post.

1 Like

if this does not help i dont no what will

so the devhub link it help you???

Ok, so just to get an understanding of what you want: A player clicks a button and their name gets added to the table and then to the SurfaceGui, but you want it so that when the player leaves, their name is removed?

If that is the case, you can try something along the lines of this:

Create an example in the SurfaceGui with example details. (Set it to not visible)
To add players, the easiest method is just cloning a frame within another frame You can use a UiListLayout to automatically position new frames.

local frameToCopy = script.Parent.frameToCopy
local playerQueue = {}

function addPlayerToList(player)
  table.insert(playerQueue, player.UserId)

  local copy = frameToCopy:Clone()
  copy.Parent = frameToCopy.Parent
  copy.PlayerName.Text = player.Name
  copy.Name = player.UserId -- So we can reference frame later
  copy.Visible = true
end)

game.Players.PlayerRemoving:Connect(function(player)
  if frameToCopy.Parent:FindFirstChild(player.UserId) then
   frameToCopy.Parent:FindFirstChild(player.UserId)
  end
end)

You may have to edit this a bit, but it should give you an idea of what you need.

3 Likes

I see what you are doing in this but will the text’s just get all bunched togehter not spread out down below?

Insert a UIListLayout into the frame or gui you are using.

1 Like

that is what i said if you need more help i got this tutorial it explains how to use it skip to this part 2:18

Queue.rbxl (33.0 KB)
Server

local QueueRemoteF = Instance.new("RemoteFunction")
QueueRemoteF.Name = "QueueRemoteF"
QueueRemoteF.Parent = game.ReplicatedStorage
local QueueRemoteE = Instance.new("RemoteEvent")
QueueRemoteE.Name = "QueueRemoteE"
QueueRemoteE.Parent = game.ReplicatedStorage




local Queue = {}
local RemoteCooldown = {}
local Current = nil


local function PopQueue()
	if #Queue >= 1 then
		Current = Queue[1]
		table.remove(Queue, 1)
		QueueRemoteE:FireAllClients("Update", {Current, Queue})
	else
		Current = nil
		QueueRemoteE:FireAllClients("Update", {nil, {}})
	end
end
local function Update()
	QueueRemoteE:FireAllClients("Update", {Current, Queue})
end


game.Players.PlayerRemoving:Connect(function(Player)
	RemoteCooldown[Player.UserId] = nil
	for i = 1, #Queue do
		if Queue[i] == Player.UserId then
			table.remove(Queue, i)
			Update()
			return
		end
	end
	if Current ~= nil then
		if Player.UserId == Current then
			Update()
		end
	end
end)


QueueRemoteF.OnServerInvoke = function(Player, bool)
	if bool == nil then Player:Kick() return end
	if Current == Player.UserId then return "You are the current player!" end
	if RemoteCooldown[Player.UserId] ~= nil then
		if (tick() - RemoteCooldown[Player.UserId][1]) < 1 then
			RemoteCooldown[Player.UserId][1] = tick()
			RemoteCooldown[Player.UserId][2] += 1
			if RemoteCooldown[Player.UserId][2] >= 2 then
				Player:Kick()
				return
			end
		else
			RemoteCooldown[Player.UserId][1] = tick()
			RemoteCooldown[Player.UserId][2] = 1
		end
	else
		RemoteCooldown[Player.UserId] = {tick(), 1}
	end
	if bool == true then
		for i = 1, #Queue do
			if Queue[i] == Player.UserId then
				return "You are already in the queue."
			end
		end
		table.insert(Queue, Player.UserId)
		local QueueN = #Queue
		Update()
		return "You've been added to the queue (#"..QueueN..")"
	else
		for i = 1, #Queue do
			if Queue[i] == Player.UserId then
				table.remove(Queue, i)
				Update()
				return "You've been removed from the queue"
			end
		end
		return "You are not in the queue."
	end
end


while wait(5) do
	PopQueue()
end

Localscript (GUI)

local QueueRemoteF = game.ReplicatedStorage:WaitForChild("QueueRemoteF")
local QueueRemoteE = game.ReplicatedStorage:WaitForChild("QueueRemoteE")


local Joined = false
QueueRemoteE.OnClientEvent:Connect(function(_type, args)
	if _type == "Update" then
		if args[1] == nil then
			script.Parent.Current.Username.Text = "Current Player: N/A"
		else
			if args[1] == game.Players.LocalPlayer.UserId then
				script.Parent.Current.Username.Text = "You are the current player!"
				Joined = false
				script.Parent.Queue.JoinButton.Text = "Join Queue"
			else
				local player = game.Players:GetPlayerByUserId(args[1])
				if player then
					script.Parent.Current.Username.Text = "Current Player: "..player.Name
				else
					script.Parent.Current.Username.Text = "Current Player: ?"
				end
			end
		end
		if args[2] == nil then return end
		local Children = script.Parent.Queue.List:GetChildren()
		for i = 1, #Children do
			if Children[i].Name ~= "Template" then
				Children[i]:Destroy()
			end
		end
		for i = 1, #args[2] do
			local Entry = script.Parent.Queue.List.Template:Clone()
			Entry:FindFirstChild("Position").Text = "#"..i
			Entry.Username.Text = (game.Players:GetPlayerByUserId(args[2][i]) or {["Name"]="N/A"}).Name
			Entry.Position = UDim2.fromScale(0, Entry.Size.Y.Scale*(i-1))
			Entry.Visible = true
			Entry.Name = i
			Entry.Parent = script.Parent.Queue.List
		end
	end
end)


local JoinCD = true
script.Parent.Queue.JoinButton.MouseButton1Click:Connect(function()
	if not JoinCD then return end
	JoinCD = false
	script.Parent.Queue.JoinButton.TextTransparency = 0.6
	local Result = QueueRemoteF:InvokeServer(not Joined)
	if Result ~= nil then
		if Result == "You are not in the queue." then
			Joined = false
		elseif Result == "You are already in the queue." then
			Joined = true
		elseif Result:sub(1, 33) == "You've been added to the queue (#" then
			Joined = true
		elseif Result == "You've been removed from the queue" then
			Joined = false
		elseif Result == "You are the current player!" then
			Joined = false
		end
		local OriginalText = script.Parent.Queue.JoinButton.Text
		for i = 2, 1, -1 do
			script.Parent.Queue.JoinButton.Text = Result.." ("..i..")"
			wait(1)
		end
		script.Parent.Queue.JoinButton.Text = Joined and "Leave Queue" or "Join Queue"
	else
		local OriginalText = script.Parent.Queue.JoinButton.Text
		for i = 2, 1, -1 do
			script.Parent.Queue.JoinButton.Text = "Error ("..i..")"
			wait(1)
		end
		script.Parent.Queue.JoinButton.Text = Joined and "Leave Queue" or "Join Queue"
	end
	wait(1)
	script.Parent.Queue.JoinButton.TextTransparency = 0
	JoinCD = true
end)

Come on man stop being rude to others this is dev hub not roblox forum if the person is not understanding you had to understand him he is in trouble learning it.

1 Like