Why is an error being given saying this doesn't exist but does?

game.ReplicatedStorage.Farming.SeedFinder.OnClientEvent:Connect(function()
	warn("Recieved Call")
	for i,v in pairs(game.Players.LocalPlayer.PlayerGui.ScreenGUI.Inventory.Slots:GetChildren()) do
		if v.ItemName.Value == game.ServerStorage.Values.SelectedSeed.Value.." Seeds" then--This line is the one causing the error
			warn("Found Seed and now doing stuff with it")
			v.Count -= 1
			script.Parent.Plant:FireServer()
			break
		end
	end
end)

The line giving the error says that Values is not a valid member of ServerStorage “ServerStorage”. That folder does in fact exist however, and I have checked both while the game is running and when it’s not. I tried :WaitForChild(), but that game me an infinite yield message, and :FindFirstChild() gave me a separate error saying that the SelectedSeed value was nil. What is wrong here and how can I fix it?

ServerStorage is located on the server, you can’t access it from a LocalScript. Use ReplicatedStorage, which is replicated.

As @JarodOfOrbiter said: you cannot access ServerStorage on the client.

ReplicatedStorage should be used instead since like @JarodOfOrbiter also said, it is accessible to both the server and client, meaning the client and server can view and access everything inside of it.

What I need to do is access a GUI (Client) and try to match it up with the variable’s value (server). What can I do instead then?

You simply just need to place that value in ReplicatedStorage, so the client and server can access it.


If you need to get a value on the Client that is only available on the Server, you could use a RemoteFunction.
Here is an example:

Server Script

FUNCTION.OnServerInvoke = function(plr)
     return "abc"
end

LocalScript

local value = FUNCTION:InvokeServer()
print(value) -- prints "abc"

Or, as @AmoraFolf said in the above reply, you can place the value inside the ReplicatedStorage so it can be used by both.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.