Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Any possible way of saving Instances with DataStore?

Asked by
coo1o 227 Moderation Voter
10 years ago

Now before you say it, I know you can't save Instances with DataStore like so:

game:GetService("DataStoreService"):GetDataStore("ds"):SetAsync(workspace.Part)

But I want to know if there are any POSSIBLE ways? As it says on the wiki:

You should write a function that converts the instance to a table or string.

So is this possible or not?

Thanks!

~coo1o

1 answer

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

Basically, you save all the relevant properties of the Object you want to save in the form of a Table or JSONified table, and write a function that takes this table and creates actual bricks out of it.

For example:

PartsToSave = {
    Part1 = {
        Name = "Test",
        Reflectance = 0,
        Transparency = 0, Size = {20, 15, 6) --[[Tables can't contain ROBLOX Instance to be DataStore'd IIRC]],
        Position = {256, 2, 10},
        Rotation = {2, 0, 0}};
    Part2 = {...};
} --And so on

Using this table and nested generic for loops using the pairs iterator function (since ipairs doesn't for non-numeric indexes), you can Instance.new() the parts and set the relevant properties.

I suggest giving PartsToSave direct subtables of the Parts' types, namely Wedges, Trusses, and just Parts, to make the loops simpler.

1
Thanks! coo1o 227 — 10y
Ad

Answer this question