Accessing Server Storage From a Client

I am trying to clean up my workspace, and I’d like to access server storage from a remote function on the client-side.

The issue is that although I’ve followed all steps correctly, (I’ll elaborate in a moment) I can’t seem to return an instance from the server Storage, to a client.

I have tried to debug, by placing prints before each line to find the result, which is always nil on the clientside.

TL;DR:
I have a module, on the client-side, that sends a remote function to a serverside module, which then returns a value from the item database. The item is sent back to the serverside module, which then returns the item to the client. Which always returns nil.

I did some reading, and was able to fix it by sending it to the repstorage (Since this was what seemed to be my only option in the API documenation) momentarily using Debris(AddItem, 3) which then allows the item to be returned to the client (Since I can pull stuff from repstorage on the client side)

My question is, How the heck do I avoid this workaround? I want to access my items without replicating them first.

D̶i̶d̶ ̶y̶o̶u̶ ̶r̶e̶q̶u̶i̶r̶e̶ ̶t̶h̶e̶ ̶s̶e̶r̶v̶e̶r̶ ̶s̶i̶d̶e̶ ̶m̶o̶d̶u̶l̶e̶ ̶f̶i̶r̶s̶t̶?̶

yes. I can return the item. Just not directly from server Storage

I had to clone it first.

Stuff in the ServerStorage only exists on the server. Why not just put the items into ReplicatedStorage in this case?

I don’t think you can return server items to the client directly. You might have to use an alternative method such as cloning it and parenting it to a place where the client can see it (ReplicatedStorage).

What are you exactly trying to do? Could you describe an example of the item or something that we can possibly try referencing from?

thats what I ended up doing.

I dont want to save it to the rep storage for security reasons. Its my item database.

The problem is, objects in ServerStorage don’t replicate to the client. If you’re returning something like game.ServerStorage.Thing to the client, you’re not actually returning the object–you’re just returning a reference to the object, which the client can’t see. The purpose of putting it in ReplicatedStorage is so it can be gotten by the client - that’s the reason ReplicatedStorage exists.

If you’re concerned about players being able to just copy all of the items in ReplicatedStorage, then your idea of only moving one item over at a time if the player is allowed to access it is your best bet.

4 Likes

is there a better solution than cloning it, and deleting it after a few seconds? what if the server lags, and the client doesnt get the item before its destroyed?

well anyway, Thank you for your assistance everyone :slight_smile: at least I know now, that I did things as best as I could lol.