DataStore2 Help

--// DataStore2 
local DataStore2 = require(script.DataStore2)
--// Default Values
local DeathCount = 0
local XashCount = 10000
local LevelCount = 1

-- Metatable
local tab = {}

	local XashData = DataStore2("Xash", plr)
	local DeathData = DataStore2("Death", plr)
	local LevelData = DataStore2("Level", plr)
	-- Metamethods
		__index = function(t,k)
			local folder ="Folder")
			folder.Parent = plr
			folder.Name = "leaderstats"
			local Xash ="IntValue")
			Xash.Parent = folder
			Xash.Name = "Xash"			
			local Level ="IntValue")
			Level.Parent = folder
			Level.Name = "Level"
			local Death ="IntValue")
			Death.Parent = folder
			Death.Name = "Death"
			return k
	print("Indexing metamethod "

	local function saveDeath(update)
		plr.leaderstats.Death.Value = DeathData:Get(update)
	local function saveXash(update)
		plr.leaderstats.Xash.Value = XashData:Get(update)
	local function saveLevel(update)
		plr.leaderstats.Level.Value = LevelData:Get(update)

What am i doing wrong, i get an error saying

[ServerScriptService.Script.DataStore2:368: attempt to index local ‘tableResult’ (a number value)

Have a look in the Output, it should say what line it is. Then check to see if there is a red line under any of the words on X line.


Okay so, you click the red text and it should direct you.

So, when you’re combining you should be using a master key. Right now it looks like you’re missing it so you should do DataStore2:Combine("DATA", "Xash", "Death","Level") instead of DataStore2.Combine("Xash","Death","Level"). Be sure to reference Datastore2’s documentation in the future.

i get an error when i do that, plus in the site it says to do

DataStore2.Combine(masterKey, ...keysToCombine)

What error do you get? I replicated your code using the latest version of DataStore2 and it works fine for me. And yes, that’s what the site says and that’s what I’ve given you. In the sample I gave you DATA is the masterKey and everything else are the keysToCombine.

When i do DataStore2:Combine() then i get

[23:13:29.656 - ServerScriptService.Script.DataStore2:483: DataStore2() API call expected {string dataStoreName, Instance player}, got {table, Instance}]

Using the master key like this is undefined:

You should not be using the master key as a normal key, it should only ever be referenced in DataStore2.Combine.

1 Like