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

How do I get a list of all the player's in the server on a ScrollingFrame?

I want to get the list of all players that are in the game in a ScrollingFrame in a ScreenGui, how would I go about doing this? The "templateBtn" is the button that contains the player's name.

https://gyazo.com/75bdbdefcd0dddadd3d8d7522eed7bee

2 comments

0

I would awnser,but i dont know how to post you the code. is it inline code or code block

0

You just take the code as you see it in a script, copy it, and paste it in the "Answer this question" box. Then you select it all and click the "Lua" button to the right of the "C".

2 answers

✓ Accepted answer
--// GetService is a handy tool that returns the service no matter what (in case the service is renamed etc)
local SG = game:GetService("StarterGui")
local Players = game:GetService("Players")

local GUI = SG.fnrGui.servingFrame.playerlist --// Assuming from the screenshot
local Btn = GUI.templateBtn:Clone()
GUI.templateBtn:Destroy() --// The Instance is not needed anymore

Players.PlayerAdded:Connect(function(player) --// When a player joins the game it fires the function.
	local Btn = Btn:Clone()
	Btn.Text = player.Name
	Btn.Parent = GUI
end)

for _,player in pairs(Players:GetPlayers()) do --// Needed when testing in solo mode.
	local Btn = Btn:Clone()
	Btn.Text = player.Name
	Btn.Parent = GUI
end

This script makes a clone of your templateBtn and destroys the original. Once a new player joins the game and if there is any players it makes new templateBtns and changes the Text property to their name. Also I'm assuming from the screenshot that you don't need to position the new part because of the UIGridLayout Instance.

Hope this helps.

2 comments

0

Thanks! It works c:

0

No problem.

p=game.StarterGui.ScreenGui.ScrollingFrame--repplace  this with location of your scrolling  frame that you want the players to be on
game.Players.PlayerAdded:connect(function()--when a player joins the game it fires this event
g=+1
b=Instance.new("TextButton",p)--makes a new text button when a player joins
b.Text=game.Players.LocalPlayer.PlayerName--makes the text the player's name
b.Position=g*60--makes the text button position (down) increase 60 each time a player joins,since each time a player join,g is increased by 1
end)--ends the event

when a player joins a new textbox is created for a players name.And the position goes down by 60 for each time.Friend me im danielp533 im a great scripter and happy to help.Tell me if it dont work

3 comments

0

There's an error on line 3 where the + is

0

The script also wouldn't properly position a frame since all GUIs require a UDim2.new() function. I'll see what I can do, Shi.

0

dude i just gave you the basics turn +1 to 0+1 and finish the instancing statememt

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