Datastore2 converting string to table

Boosting because its been 7 hours.

2 Likes

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.

2 Likes

Boosting because it has been 16 hours.

2 Likes

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

2 Likes

arent u supposed to use :GetAsync
not
:Get

2 Likes

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

2 Likes

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.

2 Likes

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"]
end

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)
	print(wallet:Get(player))
	return wallet:Get(player)
end

walletReturn.OnServerInvoke = returnWallet
game:GetService("Players").PlayerAdded:Connect(function(player)
	returnWallet(player)
	wallet:Update(player, 5)
	returnWallet(player)
end)```
1 Like

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

1 Like

image

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:

It’s that second call that is the problem. The routine calls it for EconomyDatabase which is a string. Then in the code it calls it again with this statement:

local dataStore = DataStore2(combinedDataStoreInfo[dataStoreName], player)

My code would then print out:

DATA string

Somewhere I think your DATA value got corrupted or something. You might be able to start fresh and change the data store name like so:

datastoreService:Combine("DATA2", "EconomyDatabase")