What do you want to achieve? Keep it simple and clear!
I want to create a playerlist for my ban system. I thought it worked, but for some reason, it doesn’t.
What is the issue? Include screenshots / videos if possible!
I’m not even entirely sure but when i go to make a local server with anything above 1 player, it does
add to the player list but then your player info just doesnt exist. I thought maybe this had to do with all players joining at the same time, but even that raises an issue that i don’t want even if it might rarely happen.
local scroll = script.Parent
local rss = game:GetService("ReplicatedStorage")
local placeholder = rss.GUI.Placeholder
local function updatePlayers()
local playerFrame = placeholder:Clone()
for i, child in pairs(scroll:GetChildren()) do
if child:IsA("ImageButton") then
child:Destroy()
end
end
for i, plr in pairs(game.Players:GetChildren()) do
local img = game.Players:GetUserThumbnailAsync(plr.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size420x420)
playerFrame.displaylabel.Text = plr.DisplayName
playerFrame.userlabel.Text = "@"..plr.Name
playerFrame.icon.Image = img
playerFrame.Name = plr.Name
playerFrame.Parent = scroll
end
end
updatePlayers()
game.Players.PlayerAdded:Connect(updatePlayers)
game.Players.PlayerRemoving:Connect(updatePlayers)
On 2 player server:
Player 1:
(it should be player 2 and player 1, but its just player 2)
Player 2:
(it should be player 1 and player 2, but its just player 1)
Edit: I ALWAYS FORGET TO SAY THIS, but there is no errors!
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
The only ones with similar issues/code didn’t have my issues.
I know you’ve got the solution already but, your code is better optimized using the code I wrote below:
local scroll = script.Parent
local rss = game:GetService("ReplicatedStorage")
local placeholder = rss.GUI.Placeholder
local function AddPlayer(plr)
local playerFrame = placeholder:Clone()
local img = game.Players:GetUserThumbnailAsync(plr.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size420x420)
playerFrame.displaylabel.Text = plr.DisplayName
playerFrame.userlabel.Text = "@"..plr.Name
playerFrame.icon.Image = img
playerFrame.Name = plr.Name
playerFrame.Parent = scroll
end
local function removePlayer(plr)
if scroll[plr.Name] then
scroll[plr.Name]:Destroy()
end
end
for i, plr in pairs(game.Players:GetChildren())
addPlayer(plr)
do
game.Players.PlayerAdded:Connect(addPlayer)
game.Players.PlayerRemoving:Connect(removePlayer)
The reason this code is better is because you’re currently resetting the list every time a player gets added or removed which probably isn’t best if you’re adding an event or more to the button. You only need to add or remove 1 button each time a player joins or leaves.
It makes sense but i dont use remote events for this specifically. Instead (it took me hours to code it) i used it as a selection for actions to take like banning. I appreciate it though!