Datastore2 converting string to table

Hey, DevForum!

Recently, I was working on a economy system using Datastore2 but for some reason Datastore2 is turning my datastoreName (type: string) to a table? I’ll leave the error below, along with my code. Hopefully someone is able to help me with this as I am really confused.


12:45:54.475  ServerScriptService.UrbanLibrary.Modules.DatastoreService:485: DataStore2() API call expected {string dataStoreName, Player player}, got {table, Instance}  -  Server - DatastoreService:485
  12:45:54.475  Stack Begin  -  Studio
  12:45:54.475  Script 'ServerScriptService.UrbanLibrary.Modules.DatastoreService', Line 485 - function __call  -  Studio - DatastoreService:485
  12:45:54.476  Script 'ServerScriptService.UrbanLibrary.Modules.DatastoreService', Line 497 - function __call  -  Studio - DatastoreService:497
  12:45:54.476  Script 'ServerScriptService.UrbanLibrary.Standalone.EconomySystem.Wallet', Line 28 - function Get  -  Studio - Wallet:28
  12:45:54.476  Script 'ServerScriptService.UrbanLibrary.Standalone.EconomySystem', Line 28 - function returnWallet  -  Studio - EconomySystem:28
  12:45:54.476  Script 'ServerScriptService.UrbanLibrary.Standalone.EconomySystem', Line 41  -  Studio - EconomySystem:41
  12:45:54.476  Stack End  -  Studio


function wallet:Get(player)
	local playerDocument = datastoreService("EconomyDatabase", player)
	local savedData = playerDocument:Get({["Wallet"] = 0;["Bank"] = 0;})
	return savedData["Wallet"]

Thanks to everyone who read this, hope fully I can get some help with this.


Boosting because its been 7 hours.


We might need some more code to help you out this looks like a mess, explain what your goal here is too itd be nice

1 Like

I am confused as to why it is erroring as “EconomyDatabase” is a string, and I’m datastore 2 is erroring it calling it a table. As to my code, that is all that is needed because that is all that is running. I am calling wallet:Get and it is erroring with the error I gave. The error & script gives context for it. I am trying to figure out why it is erroring, and how to fix it.


Boosting because it has been 16 hours.


I havent played around with datastore2 at all and cant seem to find any documentation on roblox api doc, im sure the params and returns are shown where that api doc is


arent u supposed to use :GetAsync


local savedData = playerDocument:Get({[“Wallet”] = 0;[“Bank”] = 0;})
local savedData = playerDocument:GetAsync({[“Wallet”] = 0;[“Bank”] = 0;})


Datastore, and Datastore2 are different, so it is :Get not GetAsync.

1 Like

Hey! I’ve already checked the documentation, and there is nothing there to help. I’m doing it exactly like it asks.


Boosting again because I wasn’t able to get an answer and wasn’t able to fix it.

1 Like

Boosting this again after about 2 weeks.

1 Like

Which line is erroring? The only thing I can think of is that datastoreService or player are both something else, but I’m not sure.

Edit: Also, people generally don’t reply to unclear questions, so maybe clarify what you have tried so far?

1 Like

I’d agree that you aren’t showing enough code. How is datastoreService defined? I’m fairly familiar with DataStore2 and I don’t recognize that method. Why don’t you go into the DataStore2 method itself and put print statements so you know exactly what that function is getting as input. Might help understand why it thinks it is a table.

1 Like

datastoreService is Datastore2 taken directly from the github page. Player is passed through via a playerAdded event directly. The :Get() function is inside of a module.

I have tried directly editing the Datastore2 module to allow for it to go through but it just doesn’t end up saving even in the actual game.

I’ve called it from different scripts, multiple different places (such as SSS my current script location, PlayerGUI, Workspace), I’ve tried putting the string inside of a variable, both in the script and in a module script, I’ve tried directly grabbing the player from Players with Players:FindFirstChild(), I’ve tried directly accessing Datastore2 so instead of running “DatastoreService(info)” I did game:GetService(sss).LOCATIONTOMODULE(info), I’ve tried reinstalling the module.

The function above is EVERYTHING inside of the module with the exception of getting/returning the module, and getting the datastore2 module I’ll leave the code for that below.

local wallet = {}
local serverScriptService = game:GetService("ServerScriptService")

local datastoreService = require(serverScriptService:WaitForChild("UrbanLibrary"):WaitForChild("Modules"):WaitForChild("DatastoreService"))
datastoreService:Combine("DATA", "EconomyDatabase")

--// Main
function wallet:Get(player)
	local playerDocument = datastoreService("EconomyDatabase", player)
	local savedData = playerDocument:Get({["Wallet"] = 0;["Bank"] = 0;})
	return savedData["Wallet"]

return wallet

I am calling it via this script.

--// Constants
local replicatedStorage = game:GetService("ReplicatedStorage")
local walletReturn = replicatedStorage:WaitForChild("UrbanLibrary"):WaitForChild("Economy"):WaitForChild("getWallet")

local wallet = require(script:WaitForChild("Wallet"))

--// Main
local function returnWallet(player)
	return wallet:Get(player)

walletReturn.OnServerInvoke = returnWallet
	wallet:Update(player, 5)
1 Like

Could you show a picture of your Explorer window with DatastoreService and all its children?

1 Like


Here is the explorer, DatastoreService is the Datastore2 Module, Wallet is the module with the :Get function, and EconomySystem is the one calling it.

1 Like

That all looks correct to me. I’ve used DataStore2 on several projects now and have never seen this. I usually have it in the root of ServerScriptService and I always have it named DataStore2 and not DatastoreService. I can’t imagine why that would make any difference but certainly something you could try to see if it helps.

UPDATE: I just tried the reverse and replaced my DataStore2 with your directory structure and named it DatastoreService and it had no effect so that isn’t it.

1 Like

Okay one last thing to try. Add this line in the DatastoreService module and see what it prints out when you run it. Should be at about line 484:

function DataStore2.__call(_, dataStoreName, player)
	print(dataStoreName, typeof(dataStoreName))

At least you will see the offending value that it thinks is a table. You might also try using a whole new Datastore name. Maybe something got corrupted and you need to start fresh.

1 Like

Hey, Just implemented this and got a weird output. It says its a string??

  21:31:47.201  EconomyDatabase string  -  Server - DatastoreService:485
  21:31:47.201   ▼  {
                    ["ClearCache"] = "function",
                    ["Combine"] = "function",
                    ["Constants"] =  ▶ {...},
                    ["PatchGlobalSettings"] = "function",
                    ["SaveAll"] = "function",
                    ["SaveAllAsync"] = "function",
                    ["__call"] = "function"
                 } table  -  Server - DatastoreService:485
  21:31:47.201  ServerScriptService.UrbanLibrary.Modules.DatastoreService:487: DataStore2() API call expected {string dataStoreName, Player player}, got {table, Instance}  -  Server - DatastoreService:487

I am so confused :sob: