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

How to Code a Datastore so that it Saves a 'Building' that Someone has Built up for Days?

Asked by 7 years ago
Edited 7 years ago

So, for example, in this game, www.roblox.com/games/284076212/Retail-Tycoon-1-1-6 you can save and load your retail stores that you build up. I want to learn how to code that. I kind of know datastores, but I don't know how to code a datastore to save a 'place' that you have worked and built up for days. How is it possible? I know that you can't store parts, that is what the wiki said, so this is why I get confused.

1 answer

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

This can be done by storing each part's individual properties. For example, if you wanted to save a 5x5 part, you could do this:

local Data = game:GetService("DataStoreService"):GetDataStore("~PARTS")
local Part = Instance.new("Part")
Part.Name = "PartToSave"
Part.Size = Vector3.new(5,5,1)
Part.CFrame = CFrame.new(10,10,10)
Part.Parent = workspace
DataStore:SetAsync(Part.Name,  {Part.Size, Part.CFrame})

and then when you want to load it, you could do:

local Data = game:GetService("DataStoreService"):GetDataStore("~PARTS")
local PartData = DataStore:GetAsync("PartToSave")
local Piece = Instance.new("Part")
Piece.Size = PartData[1]
Piece.CFrame = PartData[2]
Piece.Parent = workspace

For more information on DataStore, read up on this article: https://scriptinghelpers.org/blog/data-store-why-you-should-get-excited

Please note that I wrote this all in the ScriptingHelper's answer section, and this was only made to give you an idea on how to do it.

Ad

Answer this question