Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

NameHolder is not a valid member of ScrollingFrame. Works solo, but not in multiplayer testing?

Asked by
attapi0 20
7 years ago

This question has been solved by the original poster.

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 my folder hierarchy

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.

0
Gosh this is embarrassing. Thanks for the pointer! attapi0 20 — 7y
0
No problem. Did I answer your question. antonio6643 426 — 7y
0
If your question is answered, please edit your question's title to include something like "[Answered]" chess123mate 5873 — 7y

Answer this question