Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to save models using data store?

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)

3 comments

0

Yes. I know it's annoying!

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?

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.

1 answer

✓ Accepted answer

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!

1 comment

0

This is very useful, but does this mean I'll have to manually set the property for each individual part?

This discussion is preserved as it was. New answers, comments, and votes are closed.