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

Simple folder content extraction?

Asked by 6 years ago

Hi, so I had this idea to create a Folder in Workspace called "Admins" and add BoolValue's inside. These BoolValue's would each be named after a person that is considered an Admin. These BoolValue's are manually added in studio, not via a running script.

Now, what I want to do is use a server-sided script to check if a user's name is found in that folder, and if so, he would (For example) receive a GUI. But, if their name isn't found in the list, nothing would happen.

I'm having issues with extracting the Children from this folder into my script, but this is what I've tried so far;

game.Players.PlayerAdded:connect(function(player)
    local folder = game.Workspace.Admins
    local name = player.Name
    if name == folder:GetChildren().Name then
        script.ScreenGui:Clone().Parent = name:WaitForChild("PlayerGui")
    end
end)

The script waits till the user joins the game, then checks if your name is in the Folder as a BoolValue, and if so, your GUI appears on your screen.

I get no errors whatsoever, the GUI just simply does not appear on my screen, nor in my Player's PlayerGui.

NOTE: I added the GUI to the Player's PlayerGui because I have no clue where else to put it to ensure the player still has the GUI upon respawn. Haven't tried a CharacterAdded function yet, could this work? Thanks!

2 answers

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

GetChildren returns a table of the children that you can iterate through to check if any child meets the requirements:

game.Players.PlayerAdded:Connect(function(player)
    local folder = game.Workspace.Admins
    local name = player.Name
    for _,v in pairs(folder:GetChildren()) do
        if v.Name == name then
            script.ScreenGui:Clone().Parent = player:WaitForChild("PlayerGui")
            break
        end
    end
end)

However, it may just be more efficient to store the admin names in a table in the script. If you need to access the admin list from multiple scripts, you can use ModuleScripts. Also, you need to look inside the player for their PlayerGui, not their name.

0
This works, thanks! I realize now I indeed checked player.Name, whilst simply "player" already connects me to the exact same path. I'm no expect in loops, but I kind of understand the way you went with the for _,v in pairs loop. Appreciate the quick response! User#20989 0 — 6y
Ad
Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

GetChildren() returns an array (table) so you would have to go through all the values of the table using pairs()

game.Players.PlayerAdded:Connect(function(player)
    local folder = game.Workspace.Admins
    for _,v in pairs(folder:GetChildren())do
        if player.Name == v.Name then
            script.ScreenGui:Clone().Parent = player:WaitForChild("PlayerGui")
        end
    end
end)

Answer this question