Hi, I’m creating a system that creates folders for players and stores values in them. However, I’m having trouble accessing it from other scripts.
This is a Script
in ServerScriptService
which works as planned:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local fireClientSetup = ReplicatedStorage:WaitForChild("fireClientSetup")
game.Players.PlayerAdded:Connect(function(p)
print('[SERVER] Attempting player setup on ' .. p.Name .. ' [' .. p.UserId .. ']')
-- Create Folder
local playerFolder = Instance.new('Folder', game.ReplicatedStorage)
playerFolder.Name = p.Name .. ' [' .. p.UserId .. ']'
print('[SERVER] Folder successfully created for ' .. p.Name .. ' [' .. p.UserId .. ']')
-- Create Player Settings
local fovSetting = Instance.new("IntValue", playerFolder)
fovSetting.Name = "fovSetting"
fovSetting.Value = 90
print('[SERVER] fovSetting successfully created for ' .. p.Name .. ' [' .. p.UserId .. ']')
local sensitivitySetting = Instance.new("IntValue", playerFolder)
sensitivitySetting.Name = "sensitivitySetting"
sensitivitySetting.Value = 1
print('[SERVER] sensitivitySetting successfully created for ' .. p.Name .. ' [' .. p.UserId .. ']')
fireClientSetup:FireClient()
end)
Here, I’m trying to access playerFolder
through a LocalScript
inside StarterCharacterScripts
:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local fireClientSetup = ReplicatedStorage:WaitForChild("fireClientSetup")
local p = game.Players.LocalPlayer
local playerFolder = ReplicatedStorage:FindFirstChildWhichIsA("Folder")
local function onClientEvent()
wait(1)
if playerFolder.Name == p.Name .. ' [' .. p.UserId .. ']' then
print("[CLIENT] Folder found for " .. p.Name .. ' [' .. p.UserId .. ']')
else
print("[CLIENT] Error when attempting to find folder")
end
end
fireClientSetup.OnClientEvent:Connect(onClientEvent)
This is the Developer Console:
Basically, if you’re still confused, I’m trying to access a folder that doesn’t exist until the script is run. I thought using FindFirstChildWhichIsA
would work, but it hasn’t.
I’d like to know why it isn’t working and how I can fix it. Thanks!