Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

2 comments

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.

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.

2 answers

✓ Accepted answer

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)

game.ServerStorage[INSERT PLAYER NAME inside the brackets]

1 comment

0

That wouldn't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.