Hey there, So I was working on an inventory system and I made the datastore for it, but it doesn’t work for some reason. I tried many things to see why it didn’t work.
[This is my first time doing datastores by the way so common mistakes might be made? ]
I don’t believe the server can access player’s UIs, since they’re cloned from the client and don’t replicate.[1] You shouldn’t store the inventory in a UI, but rather somewhere the server can access.
There’s many ways to store data, such as in a table, or a physical folder.
The client should only display data (inventory), not modify/save it.
This issue boils down onto how Roblox’s server-client model (also known as Filtering Enabled) functions. Your datastore script currently runs somewhere on the server, meaning it cannot access client-sided contents. The PlayerGui instance alongside its children are “owned” by the client, the server has no control over it.
Since you can only access datastores from the server, the client must be able to request it’s data from the server using RemoteFunctions.
Roblox has an article about how to communicate between the server-client boundary, check it out here.
A brief reminder: Never trust the client! Potential exploiters have full control over the client and they might send malicious data through remotes.
Are you referring to the behaviour of StarterGui? No, the client doesn’t clone them, the server does. The server can access Guis but it shouldn’t as Guis are primarily a client-side thing. As well, the server will not see changes that the client performs on a Gui, making server-side Gui access pointless.