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

Saving Instances with datastore?

Asked by 8 years ago

Is it possible to save parts with datastores? if so how, I've been looking high and low and I haven't been able to find anything. Could someone help me out please, Thanks in advance :)

1 answer

Log in to vote
2
Answered by
tkcmdr 341 Moderation Voter
8 years ago
Edited 8 years ago

Hey there derfvb123,

No. You cannot save instances in DataStore. The DataStore manual explicitly states that you cannot do so. You can, however, save data about the parts that you want to save. Like so:

local Part          = path.To.Part
local DataStore = game:GetService("DataStoreService"):GetDataStore("PartData")

local PartData  = {
    Position    = { Part.CFrame:components() };
    Color   = Part.BrickColor.Name;
    -- ... other properties...
}

DataStore:SetAsync("PartOne", PartData)

To render the part again, you would do the following:

local function RenderPart(partData)
    local part = Instance.new("Part", game.Workspace)

    part.CFrame = CFrame.new(unpack(partData.Position))
    part.BrickColor = BrickColor.new(partData.Color)

    -- Other setup...
end

local partData = DataStore:GetAsync("PartOne")

RenderPart(partData)

I'll leave the rest to your imagination (and ingenuity.) Have a nice day derfvb123, and best of luck with your project!

Warm regards,

tkcmdr

Sources:

CFrame API Page

BrickColor API Page

DataStoreService API Page

Global namespace/Basic functions

0
If this explanation helped you solve your problem, don't forget to mark your question as answered, bud! Thank you for using Scripting Helpers, have a nice day! c; tkcmdr 341 — 8y
Ad

Answer this question