local dataStore2 = require(game.ServerStorage:WaitForChild("DataStore2"))
local Event = game.ReplicatedStorage.Events:WaitForChild("TalkToClient")
game.Players.PlayerAdded:Connect(function(player)
local InvStore = dataStore2("Inventory", player)
Event:FireClient(player, InvStore) -- This part is saying the error
end)
That error means that you’re referencing a table that you’re storing data in inside of itself. It’s a problem because Roblox encodes tables into a json format for sending across the network and decodes them back into Lua tables at the other end, but json can’t store tables with references to themselves. You’d need to either look at how you’re storing data in InvStore and remove the cyclic table or construct a new table with all the data that you want to send.
local DataStore2 = require(script.Parent.DataStore2)
game:GetService("Players").PlayerAdded:Connect(function(player: Player)
local store = DataStore2("aaa", player)
print(store)
end)
When I print this out:
That means each datastore2 object’s savingMethod field has a dataStore2 field which likely points to itself.
You shouldn’t be sending the datastore2 object to the client anyway – data stores are server-only and so is this module.
Do you really need to send the datastore2 object to the client? The methods will not be sent. You could probably just do that if you want to send its data
Event:FireClient(player, InvStore:Get({a = 0, b = 0})) -- the default values inside of Get