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

Any possible way of saving Instances with DataStore?

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

✓ Accepted answer

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 comment

1

Thanks!

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