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

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.

This would’ve been really useful if people used it today, Roblox has been out for 2 hours and I belive DS2 works perfectly fine! :upside_down_face:

I don’t think it’ll be default “pretty soon”.

It’s something I’m going to look into at some point. File an issue on GitHub before I forget.

When I looked on the Saving Methods on the GitHub Page, It said that the saving method is Ordered Backups by default, does that mean it is kind of the same as DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. statsName)
or is Ordered Backups Completely different, if it is completely Different, how am I able to make a ordered list of the dataFrom all the players?

DataStore2 provides no way of using ordered data stores, since I’ve never needed them. The saving method is an implementation detail.

1 Like

I’m having a problem, it doesn’t seem to be saving the data correcty ( I use DataStore(“CustomInfo”,plr):Set(table) print(DataStore2(“CustomInfo”,plr):Get() and it does print the correct data, however when I rejoin, it prints a random data that I’ve never saved? Thank you for reading.

Currently having trouble, could I get some help? It seems that whenever I save the data I can’t get the data again from a place inside of the game. I use the same key and yet I’m still having trouble. Is there anything I’m missing?

1 Like

MUST not be saving, See if yo8ur code is right if it is then. idk

1 Like

If you were to add a value from another script, would the datastore still work? I am very confused about that.

1 Like

I’m certain I’m saving it because I rejoin the game and it loads all my data and then when I teleport to a place inside of the game it doesn’t load the data?!?!