This is my first time making a player list, I did use the wiki for reference and it got me this far. However, I'm getting crumbled down with all of the logic and it's screwing me up. How would I clean this up? Am I even going in the correct direction in updating a player list?
The Player List Object and it's contents - http://prntscr.com/6xv9cg
The Playerlist Gui - http://prntscr.com/6xva5g
I'm trying to add a player tab to the player list when they join, by updating the Tab with Their Player name and level. And have it updated to all players. Similar to the ROBLOX Player list.
Could anyone help me clear out the unnecessary stuff and help fix it?
function makePlayerTab(Player,PLAYER_FOR_TAB,Level,Last) local tab = game.ServerStorage.PlayerTab:Clone() tab.Parent = Player.PlayerGui.PlayerList.Holder:WaitForChild("PlayerList") -- something like this tab.PlayerName.Text = Player tab.Level = Level tab.Position = UDim2.new(0, 0,0.024, 0) return tab and spawn(function() if Last ~= nil then pcall(function() tab.Position = Last.Position + UDim2.new(0, 0,0.139, 0) end) end end) end function update(player) local Players = game.Players:GetChildren() local last; for i,v in next,Players do last = makePlayerTab(p,v,1337,last) end end game:GetService'Players'.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(c) update(p) end) end)
It looks like your algorithm is this:
It is easier than keeping track of which line is for which player and keeping them up to date, though the processing might cause lag if you keep it up to date this way.
local player = game.Players.LocalPlayer while player == nil do wait() player = game.Players.LocalPlayer end playerList = playerList:WaitForChild("PlayerGui"):WaitForChild("PlayerList"):WaitForChild("Holder"):WaitForChild("PlayerList") function reset() playerList:ClearAllChildren() end function makePlayerTab(Player,Level,Last) local tab = game.ServerStorage.PlayerTab:Clone() tab.Parent = playerList tab.PlayerName.Text = Player.Name tab.Level.Text = Level tab.Position = Last and (Last.Position + UDim2.new(0, 0,0.139, 0)) or UDim2.new(0, 0,0.024, 0) --TODO listen to input events for tab.Invite and tab.Kick return tab end function update() reset() local Players = game.Players:GetChildren() local last; for i,v in next,Players do last = makePlayerTab(p,v,1337,last) end end game:GetService'Players'.ChildAdded:connect(function(p) p.CharacterAdded:connect(update) end) game.Players.ChildRemoved:connect(update)
Main changes:
reset
and called it at the beginning of update