How can I transform my SetAsync to an UpdateAsync?

Well, I want to try to use the UpdateAsync, however, I saw that to use it you must make a separate function, but I don’t know how to put the location of the data that I want to save to that function.

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local configurationsData = DataStoreService:GetDataStore("ConfigurationsData0")

Players.PlayerRemoving:Connect(function(player)
	local Send_Data = {
		shadows = player.SettingsData.Graphics.Shadow.Value;
		water = player.SettingsData.Graphics.Water.Value;
		tree_texture = player.SettingsData.Graphics.Tree.Value;

		fps =player.SettingsData.GameSettings.FPS.Value;
		ping = player.SettingsData.GameSettings.Ping.Value;
		gamma = player.SettingsData.GameSettings.BrilloVol.Value;
		friends = player.SettingsData.GameSettings.PlayerChose.Value;
		language = player.SettingsData.GameSettings.Language.Value;
		SizeSlots = player.SettingsData.GameSettings.SlotsInventory.Value;

		crouch = player.SettingsData.Keys.Crouch.Value;
	}
	local Success, err = pcall(function()
		configurationsData:SetAsync(player.UserId,  Send_Data)
	end)
	
	if (Success) then
		print("Se ha guardado correctamente / Has been saved successfully")
	else
		print("hubo un error al guardar / there was an error saving")
		warn(err)
	end
end)

I don’t know. I recommend for complex datastores just use SetAsync
also don’t forgot to implement BindToClose

plus DataStore v2.0 now officially launced

I’m just confused, I can’t find a way to use the “DataStore v2.0”, I don’t understand how to use it

Is it basically the same one from roblox default DataStores but with 3 new features. UpdateAsync actually consider the old data before making changes to it.

Edit :- look like I also need to spend time to read the documentation again because a lot of changes already :slightly_smiling_face:

1 Like
local Success,Error
Success,Error = pcall(configurationsData.UpdateAsync,configurationsData,player.UserId,function(Data)
	--Data is the data that your game currently has saved and to update it you just need to return a new value
    --For example
	return Send_Data
end)

Hope this helps!

1 Like

mmmmmm, do you put this inside PlayerRemoving?

I mean yeah and you also should use a BindToClose function to save the data better in any case that the server closes

1 Like

So, I substitute:

by the following:

then it should look like this, right?

Players.PlayerRemoving:Connect(function(player)
	local Send_Data = {
		shadows = player.SettingsData.Graphics.Shadow.Value;
		water = player.SettingsData.Graphics.Water.Value;
		tree_texture = player.SettingsData.Graphics.Tree.Value;

		fps =player.SettingsData.GameSettings.FPS.Value;
		ping = player.SettingsData.GameSettings.Ping.Value;
		gamma = player.SettingsData.GameSettings.BrilloVol.Value;
		friends = player.SettingsData.GameSettings.PlayerChose.Value;
		language = player.SettingsData.GameSettings.Language.Value;
		SizeSlots = player.SettingsData.GameSettings.SlotsInventory.Value;

		crouch = player.SettingsData.Keys.Crouch.Value;
	}
	local Success,Error
	Success,Error = pcall(configurationsData.UpdateAsync,configurationsData,player.UserId,function(Data)
		--Data is the data that your game currently has saved and to update it you just need to return a new value
		--For example
		return Send_Data
	end)
	
	
	if (Success) then
		print("Se ha guardado correctamente / Has been saved successfully")
	else
		print("hubo un error al guardar / there was an error saving")
		warn(Error)
	end
end)

Sorry for the inconvenience, I’m a little slow doing this kind of thing.

I am not 100% sure but that should work :grinning_face_with_smiling_eyes:

1 Like

oh yeah, yes it works, thanks!