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

How to get a folder that's named "player.Name"?

Asked by 6 years ago

So I have a folder in ServerStorage that I instanced in one script and I need to reference it in another script. The folder's name is set to player.Name.

The problem the folder is created for each player in the server so if I were to reference the folder in another server script how would I get the particular folder that's named after the local player?

0
So you’re saying you want to get the player’s folder in a server script but don’t know how to get it? If so, it depends on what you’re using that folder for. User#20279 0 — 6y
0
Not the player's folder. Just a normal folder that I named after the player. I'm using it for the player's stats. xXrawr_xdXxOwO 24 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

You'd simply use FindFirstChild(). You could also use WaitForChild() but if your folder doesn't exist it'll yield forever.

local ServerStorage = game:GetService("ServerStorage")

local function FindFolder(playerName)
    local folder = ServerStorage:FindFirstChild(playerName)

    if not folder then 
        print("Folder does not exist")
    else
        print("Folder "..playerName.." was found.") 
    end
end

game.Players.PlayerAdded:Connect(function(Player)
    FindFolder(Player.Name)
end)
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

game.ServerStorage[INSERT PLAYER NAME inside the brackets]

0
That wouldn't work. xXrawr_xdXxOwO 24 — 6y

Answer this question