Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Custom Player List help?

I'm working on a custom player list for my game and I need some help with it.

local numberOfSlots = {}
local scrollingFrame = script.Parent

function addSlot(thePlayer)
    local Slot = game.ReplicatedStorage.NameFrame:Clone()
    Slot.PlayerName.Text = thePlayer.Name
    local slotPos = Slot.Position
    local slotSize = Slot.Size
    Slot.Position = UDim2.new(slotPos.X,slotPos.Y,(slotSize.Y.Scale * #numberOfSlots))
    table.insert(numberOfSlots, #numberOfSlots +1)
end


for i,v in pairs (game.Players:GetPlayers()) do
    if v:IsA("Player") then
        addSlot(v)
    end
end

I'm trying to make it so that there's a player block gui for each player, and they're all spaced apart. It's not working very well though. I tried a 2 player server and for player 1, only their name showed up on the playerlist. For player 2, both names showed up but they weren't spaced apart, the name guis were in the same position. No output errors, server side of client side. Help please?

1 answer

Okay so the problem your facing is quite simple to fix, first of all, to reduce lag and unnecessary scripting get rid of the whole loop. The first thing you want to do whenever the player loads into the game is to go ahead and create your leader board accounting for all of the players in the game. You've already done this pretty much, here's a sample script i've done to represent that.

local numberOfSlots = {}
local scrollingFrame = script.Parent.ScrollingFrame

function addSlot(thePlayer)
	local Slot = Instance.new("TextLabel", scrollingFrame)
	Slot.Size = UDim2.new(1,0,0.055,0)
	Slot.Text = thePlayer.Name
	Slot.BackgroundColor3 = Color3.new(255/255,255/255,255/255)
	Slot.TextColor3 = Color3.new(0/255,0/255,0/255)
	Slot.Font = "SourceSansBold"
	Slot.FontSize = "Size36"
	local slotPos = Slot.Position
	local slotSize = Slot.Size
	Slot.Position = UDim2.new(slotPos.X,slotPos.Y,(slotSize.Y.Scale * #numberOfSlots)) -- --What this line is doing is multiplying the height of the label I'm using and multipilying it by the number of slots already present inside of the player list so that it's directly underneath the last slot. If you want to add a gap simply add onto that number.
	table.insert(numberOfSlots, #numberOfSlots +1)
end


for i,v in pairs (game.Players:GetPlayers()) do
	if v:IsA("Player") then
		addSlot(v)
	end
end

So as shown in that sample script, whenever the player first joins the game it creates the leader board accounting for all of the players already inside of the game. Now, to add any players that join the game you simply add this line of code:

game.Players.PlayerAdded:connect(function(player)
	addSlot(player)
end)

Hopefully this fixes any problems you were experiencing, if you're still confused on anything just tell me what you still need help with and I'll see if I can.

3 comments

0

I modified your code a bit and ran into some issues. I updated the code in the original question. Basically, all the players show up now, but the frames for each player still stack.

0

I modified your code a bit and ran into some issues. I updated the code in the original question. Basically, all the players show up now, but the frames for each player still stack.

0

I've double checked my code but I don't seem to be getting any frames stacking, and if they are I'm not sure why.

This discussion is preserved as it was. New answers, comments, and votes are closed.