DataStore2 Attempt to call a table value

I’m having a problem with writing a dictionary inside a dictionary using datastore2
I’m using GetTable()

I want to write a dictionary inside of purchases using Set() but it’s giving me an error
attempt to call a table value

not the full code but you’ll get the idea

local Values = {
	Cash = 0,
	CashToCollect = 0,
	NetWorth = 0,
	Purchases = {},
	Settings = {}
}
local PlayerData = DataStore("PlayerStats",Player)
PlayerData:GetTable(Values)
local Purchases = PlayerData:Get()["Purchases"]

PlayerData:Set(Purchases{[Intance.Name] = true})

The final product I want to happen is

["Purchases"] = {["Instance"] = true}
PlayerData:Set(Purchases{[Intance.Name] = true})

Remove the curly brackets on that line. I’m not entirely sure why, but Roblox thinks putting a {…} after a variable makes said variable a function, but Purchases is table, so it errors. Curly brackets are only used when making a table itself, not accessing something in that table.

Edit: They are valid ways to call functions, sorry about that!

it gives me a syntax error if I remove the curly brackets

image

Change that line to

Purchases[a.Name] = true

PlayerData:Set(Purchases)

Roblox doesn’t allow you to set the value of something while in the brackets of a function.

You would have to store the GetTable table, make the edits to the purchases in the stored table, then set their player data to the stored table.

Your use of DataStore2 would likely be easier using combine rather than storing everything in a table.
https://kampfkarren.github.io/Roblox/api/

1 Like

There are several ways to call functions.

func""
func{}
func()

The specific ones such as “” and {} are intended for calling functions with only one parameter of that type.

1 Like

The same thing happens here’s the chunk of the code

function RestoreTycoon(Player,Tycoon)
	local PlayerData = DataStore("PlayerStats",Player)
	
	for _,a in pairs(Tycoon.Buttons:GetChildren()) do
	local Purchases = PlayerData:GetTable(DefaultPlayerValues)["Purchases"]
		if Purchases[a.Name] then
			if Purchases[a.Name] == true then
				TycoonObjects[Tycoon.Name][a.Object.Value].Parent = Tycoon.PurchasedObjects
				a:Destroy()
			else
				-- Do something
			end
		else
			Purchases[a.Name] = true
			PlayerData:Set(Purchases)
		end	
	end
	print("Finish")
end

On what line does the error happen?

PlayerData:Set(Purchases) that is where the error happens