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

Transferring Models between places?

I was reading on the Roblox Wiki about the new multi place games... And I was wondering if its possible to save objects that players built in one place and spawn it in another place.

I haven't tried coding anything so far... My video card went up in my gaming pc so I'm currently awaiting the delivery of another one. However I did read in the Wiki and there's some part about not being able to store instances but creating a function that adds them to a table.

So my question is... Is it possible to transport player built models from one place to another using Data Stores?

2 answers

✓ Accepted answer

Yes it is very possible. The best way to accomplish this is to create a table of properties to save. Remember that you cannot save any type of userdata either, so properties like CFrame and BrickColor will have to be saved a different way.

Here is some example code

local function PartToTable(Part)
	local Table = {} -- table that will hold all the properties
	local NormalProperties = {"Transparency", "CanCollide"} -- Non userdata properties of a part. I just added a couple
	
	for i,v in pairs(NormalProperties) -- loop through the basic properties
		Table[v] = Part[v] -- Add to table
	end
	
	-- Custom properties
	
	Table["CFrame"] = {Part.CFrame:components()}
	Table["BrickColor"] = Part.BrickColor.Name
	return Table
end

local function TableToPart(Table)
	local Part = Instance.new("Part")
	
	for i,v in pairs(Table) do
		Part[i] = v -- set the basic properties
	end
	
	Part.CFrame = unpack(Table["CFrame"]) -- set the userdata properties
	Part.BrickColor = BrickColor.new(Table["BrickColor"])'

	return Part
end

Let me know if you have any questions about the example code I provided.

6 comments

0

Okay I haven't coded roblox a day in my life lol. But I'm going to try and decipher this code....

0

Oh well I didn't really write it for use so it might have some errors. I also didn't write anything with datastores because I assumed you knew how to do that yourself.

0

So I can understand what I'm looking at. You have two functions one that saves the part to a table and one that creates a part from a table. Your converting the parts properties that you can save to the primary table and creating additional tables for the ones you cannot... You then retrieve the part in the function that generates the part and set its properties... As I can see your using a for lo

0

I don't feel like retyping that last part so..... Would coding this way be enough to handle more then 100+ parts to generate a single model from a table? And if you call a function before saving the table could you possibly save user data? Forgive me I can't run any tests at the moment cause my PC has 64 mb of video memory.

1

I'm not sure if this would be able to handle 100+ parts to be completely honest. There's no way to save a userdata value directly. But you can do things like save "Bright red" instead of BrickColor.Red().

0

So if I wanted to save models of that caliber it'd be best to use the Data Persistence save instance.

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