Obscure data store error when saving a table from module script

I’m trying to figure out what causes this obscure error to show up, but without any success so far

function PlayerDataStore.Save(Player: Player)
	local PlayerData = ServerStorage:WaitForChild("PlayerData")[Player.UserId] -- ModuleScript
	local Data = require(PlayerData)
	
	local Success, Error = pcall(function()
		return DataStore:SetAsync(Player.UserId, Data)
	end)
	
	if Error then
		error(Error)
	end
end)

I’m clueless what does this even mean:
зображення
(note: it’s randomized with each attempt to save)

Can you send the table’s creation structure

it is taken from a template module script for player data

-- Player Data Template
return {
	Status = {
		Staff = false,
		Banned = {
			Active = false,
			Reason = ""
		}
	},
	
	GameTime = {
		Total = 0,
		Current = 0,
		Longest = 0
	},
	
	Settings = {} -- Default settings
}

This works for me maybe there is only one entry that doesn’t work?

Are you saving the Data as a Table?

i’m requiring the module script which then returns a table. AFAIK roblox’s data store supports storing tables

Yes and No, you can save tables by converting it into JSON. you can do this by doing it like this:

local HTTP = game:GetService("HttpService")

local a = {Sample = 123}

local encode = HTTP:JSONEncode(a) -- use JSONDecode to make it table/dictionary again.

print(type(encode)) -- string

same error but different result now
зображення

result from the new code:

result from the old code:
зображення

are you sure that the :JSONEncode() is necessary? both versions of the code output the same error. also I realized the data saving still works regardless of it

how about handling the error like this:

function PlayerDataStore.Save(Player: Player)
	local PlayerData = ServerStorage:WaitForChild("PlayerData")[Player.UserId] -- ModuleScript
	local Data = require(PlayerData)
	
	local Success, Error = pcall(function()
		return DataStore:SetAsync(Player.UserId, Data)
	end)
	
	if not Success then -- changed here
		warn(Error)
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.