Allow players to save and load settings using DataStore

Objective:
I’m trying to build an experience where players can configure cars.

  • Default config: when they first join, a default car config is loaded for them
  • Customizing: players can change attributes like color, name, description
  • Saving: Players can save their car config
  • Listing: Players can see a list of their saved configs
  • Loading: Players can load a config which will be applied to their car

Sample config is a table like this:

--- Car Config Psuedo-Code
local settings = {
	name = "Car 1",
	nameKey = "Car1",
	description = "Your default car",
	colors = {
		["Back"] =  Color3.new(1, 0.25098, 1),
		["Right"] =  Color3.new(1, 0.25098, 1),
		["Left"] =  Color3.new(1, 0.25098, 1),
		["Top"] =  Color3.new(1, 0.25098, 1),
	}
}

Issue:
I am completely lost on the best approach to saving and loading this kind of configuration data to the server. Specifically, how to trigger the save/load from the client side.

What I’ve tried:

  • Basic DataStore tutorials - can save and load individual attributes like “Player Gold” but only on player connect and player leave. Need to be able to have the player manually trigger saves / list / load.
  • Remote Events tutorials - Can’t figure out how to send and receive more complex data payloads (cobfigs or list of configs)

Request:
I’m not looking for script or full solutions, but if you can provide pointers to helpful approaches, methodologies, or dev docs it would be much appreciated, thank you!

I don’t completely understand what you’re saying, so bear with me.

I use ProfileService for most of my games, so that is what I’ll be using.

  • Default config: when they first join, a default car config is loaded for them
    In ProfileService, you can set a template for the player’s data if the player is brand new.
local ProfileTemplate = {
    Cars = {{
	name = "Car 1",
	nameKey = "Car1",
	description = "Your default car",
	colors = {
		["Back"] =  Color3.new(1, 0.25098, 1),
		["Right"] =  Color3.new(1, 0.25098, 1),
		["Left"] =  Color3.new(1, 0.25098, 1),
		["Top"] =  Color3.new(1, 0.25098, 1),
	}
}}
}
local ProfileStore = ProfileService.GetProfileStore(
    "PlayerData",
    ProfileTemplate
)
-- etc, etc...
  • Customizing: players can change attributes like color, name, description
    Using a RemoteFunction, you can do this!
    Client:
local Remote = game:GetService("ReplicatedService"):WaitForChild("CustomizeCar")
-- ... do whatever like clicking a button, etc.
Button.MouseButton1Click:Connect(function()
	Remote:InvokeServer("Car1", {
			["Back"] =  Color3.new(1, 1, 1),
			["Right"] =  Color3.new(1, 0, 1),
			["Left"] =  Color3.new(1, 1, 1),
			["Top"] =  Color3.new(1, 1, 1),
		})
end)

Server

local Data = require(PATH) --Custom path to a modulescript that retrieves the player's data
local Remote = game:GetService("ReplicatedService"):WaitForChild("CustomizeCar")

Remote.OnServerInvoke = function(Player, nameKey, colors)
	-- ... do checks like seeing if they own the car
	local Profile = Data:Get(Player)
	if not Profile then
		return false
	end
	local car
	for _, v in pairs(Profile.Data.Cars) do
		if v.nameKey == nameKey then
			car = v
		end
	end
	car.colors = colors
	return true
  • Saving: Players can save their car config
    You can follow a tutorial on this, like the ProfileService setup tutorial. It’s pretty simple.
  • Listing: Players can see a list of their saved configs
    You can do this by basically doing the same thing as you did by customizing.
    Client fires remotefunction to get all their cars → server returns every car the player owns → client takes that information and lists it in ui.
  • Loading: Players can load a config which will be applied to their car
    Same with saving.

I apologize if this wasn’t what you were looking for!

What do you mean by this?

2 Likes

Much appreciated. I was hestiant to post because I wanted to clearly explain the challenge. I looked at some of the module (Like ProfileService) but couldn’t quite undertstand the usage. I’ll check out your examples and try an implementation test, thank you.

Regarding your last question: Many of the examples I’ve tried involve binding to playerConnet or PlayerLeaving from server side, which doesn’t allow for client initiated saving of configs or loading configs.

2 Likes

Just wanted to say thanks. Many hours later, I have some working tests and a handle on what to do. In the end, it was the remote functions that I was looking for, but implementing the ProfileService made it much easier to manage and more robust.

2 Likes

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