Can't get item from folder with name

Hello, I am currently trying to make a more secure way of storing player data in my game by storing it in the server storage in a folder name to players name. When trying to required the folder from another folder it is not working saying:
attempt to index nil with 'FindFirstChild’

Here are the important parts of each script:

local playerFolder = Instance.new('Folder')
playerFolder.Name = player.Name
playerFolder.Parent = playerFolders 
-- PlayerFolders is the name of the parent folder for all player folder
local playerFolder = playerFolders:FindFirstChild(player.Name) 
-- This is were the error is coming from ^^^

I have check that the player name is the same as the folder name and can’t figure why this error is happening as both of the names are exactly the same.

Thanks for the help :slight_smile:

EDIT:
Script which error is coming from

local ServerStorage = game:GetService('ServerStorage')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

local playerFolders = ServerStorage:FindFirstChild('PlayerFolders', true)

local eventsFolder = ReplicatedStorage:WaitForChild('Events')
local onTomeReadEvent = eventsFolder:WaitForChild('OnTomeRead')

onTomeReadEvent.OnServerEvent:Connect(function(player)
	local playerFolder = playerFolders:FindFirstChild(player.Name)
	local mana = playerFolder:FindFirstChild('Mana')
	
	mana.Value = mana.Value + 1
end)

Why don’t you try to refer to the playerfolder variable, nonspecific to the player name?

where is playerFolders defined? I would expect something like this at the top of both scripts

local playerFolders = workspace.ServerStorage.playerFolders

It is the right folder, I have checked that

Could you show the entire script where the error is coming from? playerFolders is nil but I have no idea why unless I can see more

2 Likes

Can you show us the full code?
Especially the playerFolders variable.

Can you also give us the locations of both scripts?

Check new edit, added the full scripted

Yeah looks like “PlayerFolders” just isn’t a descendant of ServerStorage, check your spelling? The first script will not error because setting a parent to nil is allowed.

you can’t access server storage from local script.

OnServerEvent would error on a local script, so it must be server-side

oh, i see.
@Brixogon , try replace
local playerFolders = ServerStorage:FindFirstChild('PlayerFolders', true)
to
local playerFolders = ServerStorage:WaitForChild('PlayerFolders')

and look at first letter of names, you can confuse PlayerFolders with playerFolders
(this is important)