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
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)
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.
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)