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

How to save models using data store?

Asked by 9 years ago

Hello, I'm trying to figure out how to save models and load them for later (in-game). I've been told this is possible by saving the properties of the model's children, but I don't know how to do that. Can anyone help? Here's my code (uses data persistence, which is deprecated).

script.Parent.MouseButton1Click:connect(function()
    if game.Players.LocalPlayer.DataReady == true then
        local house = game.ReplicatedStorage.AverageHouse:Clone()
        house.Parent = workspace
        game.Players.LocalPlayer:SaveInstance("House", house)
        game.Players.LocalPlayer.PlayerGui.HouseGUI:Destroy()
    else print("wait")
    end
end)
0
Yes. I know it's annoying! EzraNehemiah_TF2 3552 — 9y
0
Aw man! This is gonna be a problem for me since the models I plan to save are fairly big. Is there any other way to do this? IcyArticunoX 355 — 9y
0
Nope. Unless you save then as strings, e.g. model = "parent:workspace;name:Something" and then use string functions to find the name and stuff. This is more complicated so I advise you use the table idea instead. EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

You cannot save instances with datastores, you CAN save it through data persistence(You probably shouldn't do this though.) I'll show you how to save parts but through a table!

local part = workspace.Part1
local ds = game:GetService("DataStoreService"):GetDataStore("Part")

part_properties = {
["Name"] = part.Name
["Position"] = part.Position
["Anchored"] = part.Anchored
["Parent"] = part.Parent
} --Do the rest

ds:SetAsync("Part1", part_properties)
local dstable = ds:GetAsync("Part1")

local part2 = Instance.new("Part", dstable["Parent"])
part2.Name = dstable["Name"]
--Do the rest

Hope it helps!

0
This is very useful, but does this mean I'll have to manually set the property for each individual part? IcyArticunoX 355 — 9y
Ad

Answer this question