How to use DataStore2 - Data Store caching and data loss prevention

yes it can, i’m using this module myself and idk why it shouldn’t be able to as it’s just a module built around roblox’s datastore but with more secure methods of saving already done

1 Like

It’s pointless. Don’t do it.

Just :Get() and :Set().

1 Like

How would I go about restoring a previous version of data? Let’s say an update was released that broke peoples data, how would I go about restoring it to an older version- say a day old?

1 Like

Can you also save tables with this? Or is there any other way to save, for example, what tools the player has bought? Also, how do you check if the player who joined is new?

1 Like

Yes, by using the :GetTable() and :Set functions (saving tables is not limited to these functions)

Heavily depends on how your system is set up, but as a quick reminder you can’t directly save Instances (or instances in tables) to datastores with traditional datastorage calls such as SetAsync, UpdateAsync, or IncrementAsync

You could check for a value (that is saved onto a datastore) when a player joins, if they have said value, they’ve played before, and if they don’t, then you can set the value, and do whatever you want for anyone who is new. (if you’re planning on doing this for tutorials, I suggest you don’t set said value until they’ve completed the tutorial, just in case)

2 Likes

You could try using @sleitnick’s plugin DataStoreEditor and this post that shows you how to use it with DS2, obviously this isn’t ideal for massive player counts, but it’s a start (I personally don’t really know either)

Can I turn datastore.combine into a table somehow since I’m gonna have tones of data and can I use datastore.combine multiple times in different lines?

1 Like

Three Questions:
1: Am I able to use DataStore2.Combine more than once? if so how is that benefitable?

2: Is there a way to make a stat that is already in existence, instead of making an instance?

3: Is there a way to assign a dataStore to a Value that is inside a UI element, but that element is cloned many times, like an Upgrade system that has a “CurrentUpgrade” value inside the UI, And I don’t want my datastore to interfere with other instances of the “CurrentUpgarde”?

1 Like

You can DataStore2.Combine("DATA", unpack(dataStoreKeys)) and have dataStoreKeys be a table.

Yes. As long as a key is combined before use.

1 Like

Yes, it’s the exact same thing as using it in one line.

I don’t know what you mean. DataStore2 doesn’t do anything with regards to “stats”.

DataStore2 does not use instances. Do this however else you’d normally do it.

Yo I need help

local Players = game:GetService("Players")

local DS2 = require(game.ServerScriptService.DataStore2)

DS2.Combine("DATA","Element","HasPillar")

Players.PlayerAdded:Connect(function(Player)
	local ElementStore = DS2("ElementS",Player)
	local HasPillarStore = DS2("HasPillar",Player)
	local DataFolder = Instance.new("Folder")
	DataFolder.Name = "Data"
	
	local Element = Instance.new("StringValue")
	Element.Name = "Element"
	Element.Parent = DataFolder
	Element.Value = ElementStore:Get("Fire")
	
	ElementStore:OnUpdate(function(newVal)
		Element.Value = newVal
	end)
	

	local HasPillar = Instance.new("BoolValue")
	HasPillar.Name = "HasPillar"
	HasPillar.Parent = DataFolder
	HasPillarStore.Value = HasPillarStore:Get(false)

	HasPillarStore:OnUpdate(function(newVal)
		HasPillar.Value = newVal
	end)
	
	DataFolder.Parent = Player
	
	
end)
game.Players.PlayerAdded:Connect(function(Player)
	local joinData = Player:GetJoinData()
	

	local teleportData = joinData.TeleportData
	
	if teleportData then
		
		if teleportData.Won then
		
			repeat wait() until Player.Character
			local c = Player.Character
			local DS2 = require(game.ServerScriptService.DataStore2)
			local HasPillarStore = DS2("HasPillar",Player)
			print("Newest")
			HasPillarStore:Set(true)
			c:WaitForChild("HumanoidRootPart").CFrame = workspace.NPCs["vShanksv"].Spawn.CFrame
		elseif teleportData.Won == false then
			repeat wait() until Player.Character
			local c = Player.Character
			c:WaitForChild("HumanoidRootPart").CFrame = workspace.NPCs["vShanksv"].Spawn.CFrame
			
		end
		
	end
end)

its printing so i know it reached but it doesnt work

1 Like

Hey, we’re having a problem regarding the use of DataStore in a game that we’re working on.

Basically, the game loads the data of the player when playing in Studio, but it doesn’t when doing so with the Roblox Launcher. If you would like more details about this, here’s the post: Datastores, data in game is different then what is being returned in studio - Help and Feedback / Scripting Support - DevForum | Roblox

3 Likes

Suggestion

A DataStore2 edit feature or plugin so we can easily modify DataStore2 data, kind of ike @sleitnick 's DataStore Editor plugin

1 Like

Can you use two separate tables for DataStore2? My game uses a save system where players’ statistics/preferences (e.g. coins, UI Size, Music Volume) and their inventory (all the tools they own) are separated, as I keep adding new entries to both tables through updates, making a unification of both very displeasing to deal with, as it would mean I’d have to reflush all entries in my system every time I want to add something to one of the two tables.
Thanks in advance

The best way to do this is having your keys be the save files themselves, which DataStore2 does fine, except a tad non-ergonomically.

therefore I put the tables instead of the keys?
there were actully two different datastore values

nvm, found out how to deal with all these spooky technical terms. it’s surprisingly easy!

1 Like

can you use it in local script too? like getting the number or string i guess not but you can create a folder with every properties but in numbervalue or in stringvalue

Hi! So it seems like DataStore2 doesn’t work with Deferred events. Will this be getting fixed?

Workspace.SignalBehavior will be Deferred by default pretty soon.

No, it only works on a server script as it is a DataStore system. Also, Attributes are a lot more reliable than BaseValues.