Folder returns as nil when requested from Server

I’m looking to create a system where BoolValues are loaded into a folder inside the player, and a UI is changed depending on the result, so for example, if ___ value is set to true, ___ frame becomes visible, etc.

The issue I’m facing however is the local script does not recognize the folder at all. I tried fixes such as referencing the folder in the server script, but each time returns with a similar error:

The datastore is not the problem, the values save, the RemoteEvent fires, but I can’t get it to reference the folder stored inside the player.

Server Script:

local function onPlayerJoin(player)

	local Inventory = Instance.new("Folder") 

	Inventory.Name = "Inventory"

	Inventory.Parent = player



	local money = Instance.new("BoolValue")

	money.Name = "ExampleNametag"

	money.Parent = Inventory



	local exp = Instance.new("BoolValue")

	exp.Name = "ExampleParticle"

	exp.Parent = Inventory



	local playerUserId = "Player_" .. player.UserId

	local data = playerData:GetAsync(playerUserId)

	if data then

		money.Value = data['ExampleNametag']

		exp.Value = data['ExampleParticle']

	else
		
		money.Value = false

		exp.Value = false

	end
	
	game.ReplicatedStorage.valuesDoneLoading:FireClient(player)
	print("event fired")
end

Local Script:

game.ReplicatedStorage.valuesDoneLoading.OnClientEvent:Connect(function(player)
	if player.Inventory.ExampleParticle.Value == true then
		script.Parent.Text = "You own the item!"
	end
end)

Try this inside the local script:

local exampleParticle = player.Inventory:WaitForChild(“ExampleParticle”)

Change your localscript to this:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local LocalPlayer = Players.LocalPlayer
local RemoteEvent = ReplicatedStorage.valuesDoneLoading
local TextLabel = script.Parent

--//Functions
RemoteEvent.OnClientEvent:Connect(function()
	if LocalPlayer.Inventory.ExampleParticle.Value then
		TextLabel.Text = "You own the item!"
	end
end)

The FireClient function works by firing the client of the player which is specified in the first parameter and then the wanted parameters go after that.

LocalScript Error:

In this line you do not need to add the player parameter to the OnClientEvent line because the you are not passing any parameters and the OnClientEvent automatically detects the player. Instead, you can add this line above the OnClientEvent line:

local player = game.Players.LocalPlayer

Also remove the “player” parameter from the OnClientEvent if you already haven’t.

Although looking at scripts can sometimes show you what mistakes you’ve made, I thought I’d make an explanation instead of just sending scripts. This way, it will be more easy for you to understand.

2 Likes

I appreciate it. Thanks a bunch. :slight_smile: