I'm creating a housing system where you can place furniture within the house that you own. You can place more than one instance of the same kind of furniture (assuming you own more than one of that furniture). When the furniture is placed, it is inserted into the house model. I tried to use data persistence's :SaveInstance()
and :LoadInstance()
methods to save the model as a whole to the player. When I wait for the player's data to load, nothing happens after my wait for data line. Here's an excerpt of my code:
game.Players.PlayerAdded:connect(function(player) print("PLAYER JOINED") if player:WaitForDataReady() then print("DATA READY")
The script prints that the player joined, but nothing happens after that. There is no "DATA READY"
print. Is data persistence just unusable now or is it something I did wrong?
DataPersistence is deprecated, use DataStores instead
You'll need to serialize the data for each model and then load it back later
Because you're using prebuilt assets, you're at an advantage here: You can save 2 properties per model, and you're done.
Requirements:
Assuming that all of your placed objects are under a single model or are tracked, you may use something like this (Assumes list
is an array of placed models, and that 'Player' is predefined)
local DS = game:GetService('DataStoreService'):GetDataStore(tostring(Player.userId)); local stable = {}; for i=1,#list do stable[i] = {list[i].Name,{list[i]:GetPrimaryPartCFrame():components()}}; end; DS:SetAsync('Build', stable);
Working under the same assumptions as saving, but this time assuming that the positions translate to the same place. If you need a solution where they're relative to a specific position, I can provide you with that, but extra work is not my job.
Assumes that your models are in something predefined as ModelsContainer
local DS = game:GetService('DataStoreService'):GetDataStore(tostring(Player.userId)); local stable = DS:GetAsync('Build') for i=1,#stable do local nm = ModelsContainer[stable[i][1]]:Clone(); nm.Parent = workspace; nm.CFrame = CFrame.new(unpack(stable[i][2])) end;