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

Yes.

Because it only has to load the data from PLAYER_DATA. Not multiple data stores.

Yes.

This is a problem with your code. I can’t really give much more help than that.

1 Like

This is a problem with your code. I can’t really give much more help than that.

My code:
Main Script
Server.PlayerDataHandler:StartPlayerData(player)

PlayerDataHandler

function PlayerDataHandler:StartPlayerData(player)
--Code
end

Can you give me examples that I might able to found a bug?

Is there like a call limit inside DataStore2 like the Regular DataStore?

Unless you’re using :Save, no.

Ok, and if I were, what would be the limit?

Look here, one player’s data doesn’t load at all.

1683bcd422668f8c0d9808c8599a0a79

Did you install the module script? It worked fine for me. I put it in this: Scripting Portfolio/Library - Roblox

Generally, just don’t :Save() frequently and you should be fine.

Again, this is a problem with your code, not mine. I can’t do anything with the code sample you provided since there’s literally no instructions anywhere. I would recommend reading the documentation.

I get a error with DataStore2.
image

Here’s the script.

-- Variables
local DataStore2 = require(1936396537)
local MainKey = "DataStore Attempt1"
DataStore2.Combine(MainKey,"Stats","ClickItems","BackpackItems")

-- Data Table
local function SetDataTable()
	local UserData = {
		Stats = {
			["Clicks"] = 0;
			["Gems"] = 0;
			["Total Clicks"] = 0;
			["Total Gems"] = 0;
			["Total Time Played"] = 0;
		};
		ClickItems = {
			["Wood Click"] = true;
			["Stone Click"] = false;
			["Iron Click"] = false;
			["Gold Click"] = false;
			["Diamond Click"] = false;
			["Emerald Click"] = false;
			["Obsidian Click"] = false;
			
		};
		BackpackItems = {
			["Wood Backpack"] = true;
			["Stone Backpack"] = false;
			["Iron Backpack"] = false;
			["Gold Backpack"] = false;
			["Diamond Backpack"] = false;
			["Emerald Backpack"] = false;
			["Obsidian Backpack"] = false;
		};
	}
end

-- Main
game.Players.PlayerAdded:Connect(function(Player)
	local UserData = DataStore2(MainKey,Player):Get(SetDataTable())
	
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	local Stats = Instance.new("Folder")
	Leaderstats.Name = "Stats"
	
	local Clicks = Instance.new("IntValue")
	Clicks.Name = "Clicks"
	local Gems = Instance.new("IntValue")
	Gems.Name = "Gems"
	
	local StatsData = DataStore2("Stats",Player)
	
	local function UpdateStats(UpdatedValue)
		Clicks.Value = StatsData:Get(UpdatedValue).Clicks
		Gems.Value = StatsData:Get(UpdatedValue).Gems
	end
	
	UpdateStats(UserData.Stats) -- Here's the error
	
	StatsData:OnUpdate(UpdateStats)
	
	Leaderstats.Parent = Player
	Stats.Parent = Player
	Clicks.Parent = Leaderstats
	Gems.Parent = Leaderstats
end)
2 Likes
  1. Do not require by ID. The documentation says the only recommended way to get the module is the GitHub release.
  2. SetDataTable() doesn’t return anything, so it is returning nil.
1 Like

Probably this already has been asked under all these thousands of posts but I will ask again.

Is there a way to check if the player already has data saved upon joining?

Am I able to somehow modify a player’s data while they are not in the server?

1 Like

I’m not sure what your goal here is, is this not solved with :Get()?

No. Nobody has made a contribution yet to add this functionality.

1 Like

Well, actually, by using @Crazyman32’s DataStore Editor (150 R$), accompanied by this special method of modifying DataStore2’s, you could modify a player’s data.

EDIT: updated method link for editing DS2

2 Likes

@Kampfkarren How do I do a data wipe for Datastore2? This is mainly for testing*

1 Like

If I may respond, I would suggest simply adding a function that, when you turn it on, sets all a player’s values to 0 or nil. Normally you have something that checks for data inside your data setup script, so you know when to create new data for a player without any, or when to load existing data for a player who has it. This function however, when applied would check for people who have data, and if they do, iterate through it and set it to 0, then use your normal saving method, or remove the data keys from their DataStore table, just make sure to restrict new data from being added.
To recap.
Check if a player has data (As you will already have done in order to have a functioning datastore system.)
If they have data, erase it.
If they don’t have data, then do nothing.
Test it out. Voila immediate wiping of existing player’s data whenever they join.

2 Likes

DataStore Editor got an update, so I updated the tutorial on saving DataStore2 Data. Essentially same method, but different way of going about it.

2 Likes

I’m confused on how to use this does DataStore2:Increment(1) Get it or do i need to call :Get also is it possible saving tables because i have an inventory module i made with the function .getPlayerInventory(Player) I want to override this with the saved table can someone show me an example with them saving a table?

1 Like

@Kampfkarren How do I convert my datastore into datastore2 without losing data? Currently, my datastore handles saving between 2 places and also updating the game leaderboards. So how do I convert it to datastore2 still retaining everything I have now?

1 Like

downloaded the script do i put it in server script service?

1 Like