How to save lots of data without sending too many data store requests?

I’m trying to make a data store to save the settings in my game, I don’t wanna send too many data store requests though. This is the datastore script I tried but it wont save, is there a better way of doing this?

I also get this error message: line 33, attempt to index boolean with 'lasers'

local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("Settings")

	local folder ="Folder")
	folder.Name = "settings"
	folder.Parent = player
	local lasers ="BoolValue")
	lasers.Name = "Lasers"
	lasers.Parent = folder
	local muzzleFlash ="BoolValue")
	muzzleFlash.Name = "MuzzleFlash"
	muzzleFlash.Parent = folder
	local gunLight ="BoolValue")
	gunLight.Name = "GunLight"
	gunLight.Parent = folder
	local data
	local success, errorMessage = pcall(function()
		data = ds:GetAsync(player.UserId.."-settings") or true
	if success then
		print("Successfully loaded Settings data")
		warn(tostring("Error loading Settings data: "..errorMessage))
	if data then
		lasers.Value = data.lasers
		muzzleFlash.Value = data.muzzleFlash
		gunLight.Value = data.gunLight

	local data = {
		lasers = player.settings.Lasers.Value;
		muzzleFlash = player.settings.MuzzleFlash.Value;
		gunLight = player.settings.GunLight.Value
	local success, errorMessage = pcall(function()
		ds:SetAsync(player.UserId, data)
	if success then
		print("Settings data successfully saved")
		warn(tostring("Error saving Settings data: "..errorMessage))

	print("Game is closing")
	print("Game is closed") 

My general method has been to keep a table on the server that contains player data, and then just auto-save that on an interval (every minute or so), and when the player leaves the server. I would highly recommend not sending data every time one little setting changes.

1 Like

I recommend just using Datastore2 , as it is leagues simpler and prevents data loss. I’ve never had issues with data not saving and such using this module.

Also, the reason why you are getting that error on line 33 is because of this line:

data = ds:GetAsync(player.UserId.."-settings") or true

It couldn’t obtain the data, so it just returned true, which is a boolean. Keep in mind that if a player has no saved data in a datastore, it will return nil.

1 Like

Alright I’ll have a look into datastore2