Ad
Log in to vote
0

In need of a Save Instance replacement, anyone got one?

Asked by
Cuvette 222
1 month ago
Edited 1 month ago

Hi, I've had to try using Save/Load Instance to save a players house in one of my games. The only problem is, Data Persistence is quite outdated and barely works at times, and most of the time the player houses in my game won't save but do on the rare occasion.

Not long back I remember seeing someone had done this quite easily in a DataStore and I really cannot remember the source. If anyone has a relatively quick way of saving a model to a DataStore please get back to me!

Thanks.

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
0
Answered by
tkcmdr 276 Community Moderator
1 month ago

Hey Cuvette,

You can indeed save the house data to DataStore by way of SetAsync and UpdateAsync, both methods of GlobalDataStore. The Wiki page:

http://wiki.roblox.com/index.php?title=API:Class/GlobalDataStore

Keep in mind, you cannot save instances to a GlobalDataStore. You can, however, get away with saving a tables like this to DataStore:

local position = part.Position;

{
    Position        = {
        x = position.x;
        y = position.y;
        z = position.z;
    };

    BrickColor  = part.BrickColor.Name;
    -- ...
};

Rinse and repeat for each part in the house and save each entry in a list. Publish the list using DataStore, and get it back using GetAsync. When you retrieve the list, iterate over it and use a function like this to render each entry:

local function ConvertEntry(entry)
    local part      = Instance.new("Part", path.To.Parent);
    local position  = entry.Position;

    part.BrickColor     = BrickColor.new(entry.BrickColor);
    part.Position       = Vector3.new(position.x, position.y, position.z);
end;

There are other ways you might achieve this. If your house behaves more like a tycoon, you might make an entry for each available upgrade:

-- If an item is true, it's been unlocked, and vice versa.
{
    Walls       = true;
    Roof            = true;
    KitchenSink = false;

    -- And so on.
};

Again, you'd iterate over this table and render the respective prefabricated upgrades depending on their respective upgrade values.

I highly recommend checking out the following Wiki pages to learn more:

http://wiki.roblox.com/index.php?title=API:Class/DataStoreService http://wiki.roblox.com/index.php?title=API:Class/GlobalDataStore http://wiki.roblox.com/index.php?title=Data_store

Have a nice day, Cuvette, and best of luck with your game!

Warm regards, tkcmdr

0
Thanks for the answer, I was hoping there would be a quicker way to do this, as most of the models inside the house have scripts, intValues and all sorts inside them. It would be easier to use Data Persistance if it worked properly. Cuvette 222 — 1mo
0
Ouch, bud. Sorry to hear that. I'd recommend looking into a more efficient (and easily modifiable) method to making future games. If I may, I'd like to suggest checking an example place I made: tkcmdr 276 — 1mo
Ad

Answer this question



Ad