You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I want my player info object to save and load when the player leaves the game.
- What is the issue? Include screenshots / videos if possible!
I am trying to save a player info object in a datastore but as in the title, I am getting a error saying I cannot save dictionaries in data stores.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked on the devfourm for a while for solutions and tried them, but they didn’t work.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- Constructor
function PlayerInfo.new(player)
local self = setmetatable({}, PlayerInfo)
self.Player = player
self.Key = player.UserId
self.MaxHealth = 100
self.Health = self.MaxHealth
self.Hunger = 100
self.Inventory = require(Modules.Inventory).new(player)
self:Load()
AllPlayerInfo[player] = self
return self
end
-- The method that isn't working
function PlayerInfo:Save()
local Data = {
SavedInfo = {self}
}
local success, failure = pcall(function()
MainDataStore:SetAsync(self.Key, Data)
end)
if success then
print(self.Player.Name.."'s data was successfully saved")
else
print(self.Player.Name.."'s data failed to save")
warn(failure)
end
end
