Is there an way to save data on the client?

Hey developers,

I’m currently developing a settings option for a UI and I would like the settings to save. I’m aware that I can save the data on the server using remote events but I was wondering if there is a way to save it on the client?

2 Likes

No it isn’t possible to save on the client.

(try using the remote events :sweat_smile:)

or just have the whole script on server

3 Likes

If you’re asking whether or not you can write data to a file on a player’s machine in Roblox, it is not possible. If you’re asking if you can save data to a datastore on the client, that is also not possible for security reasons. You would want to have the client fire some sort of event via a RemoteEvent and have the server validate and interpret that event.

For example, a BuyItem event would be fired by the client and checked by the server to see if the player has enough money to buy the item and would proceed to take away the cost of the item from the player’s currency count.

2 Likes

No, its not possible. I’d recommend the UI to only review the information received from the :OnClientEvent() from a remote event as a way to substitute the behavior of saving on the client. Closest you’ll get.

1 Like

It’s not possible, I recommend you just request the server by using a remote event, be careful of overloading the key, make sure to have some sort of wait time.

Also, try not to trust the client! exploiters can do anything the client can do ie. spam a remote function/event.

1 Like

An exception to this is teleport data. There are two methods of sending teleport data: through the server or through the client. This is technically a way of saving data, but it isn’t persistent. Another way of “saving” data to a client is to interact with the player. Give them a code, or tell them to copy and paste some information.

Old role playing games used to do this to save player progress before we could save any information on the server side. They would give players a long number that would be parsed to determine experience, gold, and items when they came back and entered the number. This also meant though that really smart players could exploit it, saves could be shared, and anyone could go back to a previous save at any time.

3 Likes

No and you shouldn’t be using it at all. Exploiters can modify everything on client.

2 Likes

If an exploiter wants to change their in-game settings, there really isn’t any reason to stop them. What are they going to do, corrupt their own settings? If it doesn’t affect anyone else, there’s no reason to try stopping it.

5 Likes

You cannot save a player’s data to the client, but you can send it to the server and save it in a DataStore.

As for everyone else saying that exploiters can change it. So what? Player settings are something the user is supposed to be able to change at will. Game saves and settings aren’t the same thing and shouldn’t be treated as such in games and in topics.

5 Likes

Non-important data like UI theme and FoV can be safely handled by the client, then sent to the server to be saved (via DataStore). If an exploiter messes it up and breaks their client, sucks to be them :laughing:

However, critical data like money or loot chests should ALWAYS be handled by the server. You DO NOT want exploiters messing around with this, as it can possibly ruin the entire ecosystem of your game.

In the end, it all gets sent to the server to be stored (clients can’t access DataStores for security reasons). However, constantly having to send to the server to verify will increase lag, which may get annoying when you’re just trying to change your UI colour. Client-sided = instant; server-sided = secure.

5 Likes

My game has a menu with custom graphics/volume settings and I’ve considered saving it on the server, but I don’t want players to lag on mobile after max-ing the settings on their gaming PC. It would be very useful to be able to save this data locally in this case, even if the limit is <1kb per-game. This functionality would fit well with the already existing UserGameSettings API.

6 Likes

There is no way to save completely on the client. You’ll have to use some sort of RemoteEvents or RemoteFunctions.

Here’s an example; in the game, there’s a RemoteEvent in ReplicatedStorage called “Save”.

-- Server

local replicatedStorage = game:GetService("ReplicatedStorage")
local dataStoreService = game:GetService("DataStoreService")
local players = game:GetService("Players")

-- Events
local save = replicatedStorage:WaitForChild("save")

local function save(plr)
    local datastore = dataStoreService:GetDataStore(tostring(plr.UserId))
    -- save here.
end

-- Save when the event is called.
save.OnServerEvent:Connect(function(plr) -- The first argument is always the client (player) that the event was called on.
    save(plr)
end)

-- Save when the player leaves.
players.PlayerRemoving:Connect(function(plr)
    save(plr)
end)
-- Client

local replicatedStorage = game:GetService("ReplicatedStorage")

-- Events
local save = replicatedStorage:WaitForChild("Save")

[save button].MouseButton1Click:Connect(function()
    save:FireServer() -- Call the client event.
end)
1 Like

It is possible to put your configuration data into a text box for the player to copy into Notepad, so that they can paste it back in later. HttpService can help you encode a table of data into text.

I recommend you don’t do this for important data like money though. Players may edit the values themselves in an attempt to cheat.

1 Like