Trouble with a Module

Yes, I mean, you could manually make your own serialization method, but I was just thinking if there is an easier way.

There’s this

No, that’s not what it means by cyclic. Probably an OOP table is being passed

I’m 90% sure your error is caused by requiring other modules inside a module. I don’t think your actual coding is the problem.

So I attempted it with my own method of serializtion and I got this error:
ReplicatedStorage.Datastore:33: attempt to concatenate table with string - Client - Datastore:33
Which means a table is being passed as one of the values to the Module. That may have been my initial problem.

I thought you wanted to pass a table into the datastore?
Also can you show us your new code /w serialization?

That issue seems to be resolved when I call the function via “Datastore.Save” instead of “Datastore:Save” which I was doing before.

1 Like

Ohhhh that was your problem.
The Datastore module was being passed as the data to save. That’s why

This is the “Save” function:

function Datastore.Save(key, dataName, data)
	if key and dataName and data then
		if RS:IsServer() then
			print("Save is running on the server")
			local cachedData = cache[key]
			cachedData[dataName] = data
			print(dataName)
			print(data)
			--return true
		elseif RS:IsClient() then
			print("Save is running on the client")
			local SE = Events:WaitForChild("Save")
			SE:FireServer(key..","..dataName..","..data)
		end
	else
		return false
	end
end

and this is the event handler:

Events:WaitForChild("Save").OnServerEvent:Connect(function(player, val)
	print("hi")
	local vt = string.split(val, ",")
	local key = vt[1]
	local dN = vt[2]
	local d = vt[3]
	Datastore.Save(key, dN, d)
end)

When you call a table with ‘:’, the first parameter is the table itself

This is the correct solution, mark it as the solution

Yes that was the solution to my problem the whole time. Now I need to probably rollback to how I had the remoteEvent or Function working before because currently it doesn’t fire on the server.