I have a function that fires whenever a player joins the server to add them to my player list, sort them, etc. The function relies on a folder in the same directory called "NameHolder" that contains all of the TextLabels for the player names. It clears out this folder every time the function is run so that old labels are thrown out and aren't drawn beneath the new labels.
In solo testing, this works fine. NameHolder can be used as a parent for TextLabels fine with no issues. When I try to test with multiple players, though, I run into issues. I get the error "NameHolder is not a valid member of ScrollingFrame." This only happens in multiplayer.
Here's the code (It's in a LocalScript, if that matters)
local Players = game:GetService("Players") function refreshPlayerList() if(script.parent.NameHolder) then local nameHolderChildren = script.Parent.NameHolder:GetChildren() for _,child in pairs(nameHolderChildren) do child:Destroy() end end for index,player in ipairs(Players:GetPlayers()) do --if(player ~= game.Players.LocalPlayer) then local playerLabel = script.Parent.TemplateLabel:Clone() playerLabel.Text = player.Name playerLabel.Visible = true playerLabel.Position = UDim2.new(0,0,0,250*(index-1)) playerLabel.Parent = script.Parent.NameHolder playerLabel.Name = player.Name --end end end refreshPlayerList() local function onPlayerAdded(player) refreshPlayerList() print("playeradded") end --When a player joins, call the onPlayerAdded function Players.PlayerAdded:connect(onPlayerAdded) --Call onPlayerAdded for each player already in the game for _,player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end
I feel I'm making some egregious error that I'm just not realizing. Roblox does everything pretty eccentrically so I wouldn't be surprised if I'm just failing to understand its quirks.