I want to make a value that I have stored in replicatedstorage, no longer there and personal for each player. Everything so far I feel is easy to do, but the problem is that I have to access that personal value from a server script, how would I do that?
local MAX_WEIGHT = replicatedStorage.InventorySystem.MaxWeight.Value
I assume you mean you’re creating these values via a LocalScript on the client, as ReplicatedStorage (by definition) is replicated from the server to the client, so the server has full access to it.
If a LocalScript (on the client) is creating a value in ReplicatedStorage, then it won’t be replicated to the server, so I’ll assume that’s what you mean by your question.
I’d recommend looking at RemoteEvents or RemoteFunctions.
These are the best ways of transferring data between the client and the server.
Some more documentation.
Sorry if I expressed myself badly, I mean that I want to access a value that is personal from a server script and not local, anyways thanks.
Then yes, a remote function is probably a good idea. Use :InvokeClient()
and have a LocalScript read the value and return it back to the server.
ServerScript:
local RemoteFunction = game:GetService('ReplicatedStorage'):WaitForChild('NAME_OF_REMOTE');
local ValueYouWant = RemoteFunction:InvokeClient(PLAYER);
LocalScript:
local RemoteFunction = game:GetService('ReplicatedStorage'):WaitForChild('NAME_OF_REMOTE');
RemoteFunction.OnClientInvoke = function()
return ValueYouWantToReturn;
end
This way I will be able to access a locally stored value from my server script? in other words, in the player.
That script I wrote will let your script (on the server) read a value from a client (in a LocalScript, or from an Instance that is only accessible/read-able by the client).
1 Like