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.
ERROR
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
WALLET SCRIPT
function wallet:Get(player)
local playerDocument = datastoreService("EconomyDatabase", player)
local savedData = playerDocument:Get({["Wallet"] = 0;["Bank"] = 0;})
return savedData["Wallet"]
end
Thanks to everyone who read this, hope fully I can get some help with this.
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.
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
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.
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)```
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.
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.