I made a custom player list that shows the players name with there stats. I’m trying to make it so when you click the players button “PlayerFrame”, a new profile frame pops up. Doesn’t seem to work, no errors in the output, how can I solve this?. Heres the script and a photo for an reference.
local Players = game:GetService("Players")
local GUI = script.Parent
function profileui(plr)
local frame = script.Profile:Clone()
frame.Parent = GUI.PlayerScroller
-- frame.Info.CharacterImage.Image = img
frame.Info.DisplayName.Text = plr.DisplayName
frame.Info.Username.Text = plr.Name
end
for i,v in pairs(GUI.PlayerScroller.List:GetChildren()) do
if v:IsA("Frame") then
v.PlayerFrame.MouseButton1Click:Connect(function()
local plr = Players:FindFirstChild(v.Name)
local userId = plr.UserId
--[[ local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size42x42
local img, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize) --]]
profileui(plr)
end)
end
end
Looping and getting all the children will only add the event connection for all the existing children (won’t work for example; if you started a test and a new child is added since the child wasn’t apart of the loop). But you could just create a script instance parented to the button instance… detect when the button is pressed then just call the function displaying the UI
like what the person above said, the code will only run once. to make it run everytime the playerlist updates, wrap your loop in a function called “update” or something, then connect a descendantadded event to the playerlist. when the descendantadded event runs, call your update function
it should look like this:
local Players = game:GetService("Players")
local GUI = script.Parent
function profileui(plr)
local frame = script.Profile:Clone()
frame.Parent = GUI.PlayerScroller
-- frame.Info.CharacterImage.Image = img
frame.Info.DisplayName.Text = plr.DisplayName
frame.Info.Username.Text = plr.Name
end
function update()
for i,v in pairs(GUI.PlayerScroller.List:GetChildren()) do
if v:IsA("Frame") then
v.PlayerFrame.MouseButton1Click:Connect(function()
local plr = Players:FindFirstChild(v.Name)
local userId = plr.UserId
--[[ local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size42x42
local img, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize) --]]
profileui(plr)
end)
end
end
end
update()
GUI.DescendantAdded:Connect(update)