im trying to make a custom player list in a box for a developer product, so the player name is a text button so its selectable. ive never made a plr list before so i have no idea what im doing. i appreciate any help ty
function updPlrs()
local plr = game.Players.LocalPlayer
local plrs = game:GetService("Players")
local thumbnailtype = Enum.ThumbnailType.HeadShot
local thumbnailsize = Enum.ThumbnailSize.Size420x420
local thumbnail = plrs:GetUserThumbnailAsync(plr.UserId, thumbnailtype, thumbnailsize)
for i, child in pairs(script.Parent.plrScroll:GetChildren()) do
child:Destroy()
end
for i, p in pairs(game.Players:GetPlayers()) do
local template = script.Parent.plrScroll.plrName
local templateClone = template:Clone()
templateClone.Parent = script.Parent.plrScroll
templateClone.Visible = true
templateClone.plrName.Text = p.Name
templateClone.plrName.displayName.Text = "@"..p.DisplayName
templateClone.plrName.PFP.Image = thumbnail
end
end
game.Players.PlayerAdded:Connect(updPlrs)
game.Players.PlayerRemoving:Connect(updPlrs)
should look something like this:
1 Like
Lmk if u encounter any issues or need any explanations
-- i recommend naming ur variables better and structuring ur code, it'll make your progress 100x faster
local Players = game:GetService("Players")
local template : Frame = script.Parent.plrScroll.plrName -- correct if wrong but I'm hesitating with .plrScroll and .plrScroll.plrName
coroutine.wrap(function()
local function addToList(player : Player)
local thumbnailtype = Enum.ThumbnailType.HeadShot
local thumbnailsize = Enum.ThumbnailSize.Size420x420
local thumbnail = Players:GetUserThumbnailAsync(player.UserId :: number, thumbnailtype, thumbnailsize)
local templateClone : Frame = template:Clone()
templateClone.Name = player.Name
templateClone.Parent = script.Parent.plrScroll
templateClone.Visible = true
local playerText : TextLabel = templateClone:FindFirstChild("plrName")
playerText.Text = player.Name
local displayName : TextLabel = playerText:FindFirstChild("displayName")
displayName.Text = string.format("@%s", player.DisplayName)
local profile_thumbnail : ImageLabel = playerText:FindFirstChild("PFP")
profile_thumbnail.Image = thumbnail
-- do other stuff like handle buttons
task.spawn(function()
-- btn actions?
end)
end
local function removeFromList(player : Player)
for _, playerFrame : Frame in pairs(script.Parent.plrScroll:GetChildren()) do
if playerFrame.Name == player.Name then
playerFrame:Destroy()
end
end
end
Players.PlayerAdded:Connect(addToList)
Players.PlayerRemoving:Connect(removeFromList)
end)()
2 Likes
hey man,
thanks a million for ur help!
i shouldve been clearer up above. the plrname is a textbox, not a frame. i’ve got the textbox in the scrolling frame.
i would say the problem is with the textbox? i want the text box with the player name to be selectable yk.
i just modified it a small bit:
local Players = game:GetService("Players")
local template : Frame = script.Parent.plrScroll.plrName -- correct if wrong but I'm hesitating with .plrScroll and .plrScroll.plrName
coroutine.wrap(function()
local function addToList(player : Player)
local thumbnailtype = Enum.ThumbnailType.HeadShot
local thumbnailsize = Enum.ThumbnailSize.Size420x420
local thumbnail = Players:GetUserThumbnailAsync(player.UserId :: number, thumbnailtype, thumbnailsize)
local templateClone : TextBox = template:Clone()
templateClone.Name = player.Name
templateClone.Parent = script.Parent.plrScroll
templateClone.Visible = true
local playerText : TextLabel = templateClone:FindFirstChild("plrName")
playerText.Text = player.Name
local displayName : TextLabel = playerText:FindFirstChild("displayName")
displayName.Text = "@"..player.DisplayName
local profile_thumbnail : ImageLabel = playerText:FindFirstChild("PFP")
profile_thumbnail.Image = thumbnail
end
local function removeFromList(player : Player)
for _, child in pairs(script.Parent.plrScroll:GetChildren()) do
if child.Name == player.Name then
child:Destroy()
end
end
end
Players.PlayerAdded:Connect(addToList)
Players.PlayerRemoving:Connect(removeFromList)
end)
just make a variable named selected_player and everytime someone activates (clicks) on a button it sets the variable to x player
if you want me to do it or give a snippet lmk
1 Like
i tinkered around and got something going but i have this error on this line:
templateClone.displayName.Text = "@"..p.DisplayName
local template = script.Parent.plrScroll.plrName
local plrs = game:GetService("Players")
function updPlrs()
local plr = game.Players.LocalPlayer
local thumbnailtype = Enum.ThumbnailType.HeadShot
local thumbnailsize = Enum.ThumbnailSize.Size420x420
for i, child in pairs(script.Parent.plrScroll:GetChildren()) do
child:Destroy()
end
for i, p in pairs(game.Players:GetPlayers()) do
local thumbnail = plrs:GetUserThumbnailAsync(p.UserId, thumbnailtype, thumbnailsize)
local templateClone = template:Clone()
templateClone.Parent = script.Parent.plrScroll
templateClone.Visible = true
templateClone.Text = p.Name
templateClone.displayName.Text = "@"..p.DisplayName
templateClone.PFP.Image = thumbnail
end
end
updPlrs()
game.Players.PlayerAdded:Connect(updPlrs)
game.Players.PlayerRemoving:Connect(updPlrs)