Hey so i want to make a game but there's one aspect that i am finding quite difficult. I looked for a tutorial online to try and see if i can make a player list and all i can find is one tutorial.
So i follow this tutorial, it all works fine in studio but that is because there is only one player. The problem that i have found is, players who join FIRST can see everyone's name. NEW players cannot see player names who joined BEFORE them. This is a bit hard to explain so i'm going to try do it with numbers below:
1 joins. 2 joins,
1 can see 1 + 2. 2 can only see 2.
3 joins,
1 can see 1, 2 + 3. 2 can see 2 + 3. 3 can only see 3.
I hope you can understand that. Could someone look through this tutorial i went through and perhaps aid me in fixing the list?
Tutorial i followed : https://www.youtube.com/watch?v=xWwgsn7ndik
Do something like this, storing each person who joins
game.Players.PlayerAdded:connect(function(player) --Have a folder in Lighting, or somewhere to store the values local plr = Instance.new("StringValue") plr.Parent = game.Lighting.Folder plr.Value = player.Name --That stores the player end) game.Players.PlayerRemoving:connect(function(player) if game.Lighting.Folder:FindFirstChild(player.Name) then game.Lighting.Folder[player.Name]:Destroy() end --This removes the player from the Folder when he/she leaves end)
Then just make the PlayerList based off that, do something like
game.Lighting.Folder.ChildAdded:connect(function(item) --Then just create your player frame, or clone it, for under the list, and base it off of the item that was added, "item", to get the players name, just do "local player = item.Name" end)
This should help :)
The tutorial video you watched is a decent video, but for some reason he finds it best to make every single frame and remove every one with people joining and leaving which can easily become confusing.
I think happyturk might be on the right track, but using lighting is a very old method and I would like to keep things to 1 script. He is right that you should store a list of the players, but I personally use a table as such:
function update() -- Add here all of your stuff for updating your players list. Idk how yours is designed so I can't tell you exactly how. end plr = {} -- this is the table for holding the list of players p = game.Players:GetChildren() -- a list of all of the players basically, some will disagree with GetChildren because there can be extra stuff in the players list but I never put anything extra in there. You can use GetPlayers if you prefer. for i = 1,#p do -- for every person in the game table.insert(plr, p[i]) -- insert the player from the list "p" to plr end game.Players.ChildAdded:connect(function(NewPlayer) -- when someone new joins table.insert(plr, NewPlayer) -- add the new player into the list of players update() -- Update is the name of the function I used to update the player list end) game.Players.ChildRemoved:connect(function(WhoLeft) -- when someone leaves table.remove(plr, getNumber(WhoLeft)) -- remove the player update() end) -- This creates the list of all of the players in game and keeps the list updated. Where I put "update()" I am calling a function I had to actually update the player list
If this helps answer your question, please remember to accept my answer. Otherwise comment or message me on Roblox on how I could have better helped you with your question :)
Hopefully so you can see how i did my design:
Main = script.Parent.MainFrame
PL = Main.PlayerList
Pos = 0
function upd()
wait(.1) getall = PL:GetChildren() for i=1, #getall do getall[i].Position = UDim2.new(0, 0, 0, Pos) Pos = Pos + 130 end Pos = 0
end
game.Workspace.Players.ChildAdded:connect(function(plr)
wait(.1) Frm = Instance.new('Frame', script.Parent.MainFrame.PlayerList) Frm.Name = plr.Name Frm.Size = UDim2.new(0.96, 0, 0, 130) Frm.Position = UDim2.new(0, 0, 0, 0) Frm.BackgroundColor3 = Color3.new(132/255, 106/255, 70/255) Frm.BackgroundTransparency = 0 IL = Instance.new('ImageLabel', Frm) IL.Image = 'http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&username=' .. plr.Name IL.Size = UDim2.new(0, 100, 0, 100) IL.Position = UDim2.new(0, 10, 0, 13) IL.BackgroundTransparency = 1 TL = Instance.new('TextLabel', Frm) TL.Text = plr.Name TL.BackgroundTransparency = 1 TL.Position = UDim2.new(0.275, 5, 0.154, 22) TL.Size = UDim2.new(0, 300, 0, 30) TL.Font = 'SourceSansBold' TL.FontSize = 'Size14' TL.TextScaled = true TL.TextWrapped = true TL.TextXAlignment = 'Left' TL.TextColor3 = Color3.new(255/255, 255/255, 255/255) upd()
end)
game.Workspace.Players.ChildRemoved:connect(function(plr2)
wait(.1)
if PL:FindFirstChild(plr2.Name) then
PL[plr2.Name]:remove() upd()
end
end)