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

How can i save models with DataStore?

So i am trying to make a saving system for models, but i dont know how. So how do i save models that have extra parts that were put from an remoteevent?

for ex. a player puts a random decal in an random part (every part is called part). and a player puts a new part to an model. how do isave that decal/part and then load it when the player joins?

I have not attempted to script it, because i dont know what i need/what to do.

thank you

7 comments

0

I believe it is impossible to save models in the data store

0

Try to make a datastore using the model and getting the children of the model.

1

You cannot save objects (Userdata) in datastores. Your best shot is saving the values of the properties like position, color, etc. Thus, you would have to write a function that loops through the model and saves either a string or a table of data relating to each child. Then, when you load the object from the datastore, you would have a function to convert it back.

0

How much datastore do i need? (getdatastore). Do i need one or a ton?

0

also what do you mean by converting it back? do i need to do Instance.new?

0

You can use one datastore. As for converting it back, yes, you would have to recreate all of the instances and then change their properties to those that you saved.

0

what do i need to "setasync"? there are too many parts, so how do i get the correct table?

1 answer

THIS IS NOT A REQUEST SITE BUT I WILL TRY TO HELP YOU OUT:

You can't save models directly. To save them you need to save their properties such as the name, position and or color (you could also save any decals on them).

You will need to understand PrimaryParts before doing this.

What I do is loop through the place where the models are located then insert the needed properties into a special array called a dictionary and save that. Here is an example:

local models = locationWhereModelsAre

local array = {}

for i, obj in pairs(models:GetChildren()) do
	if obj then
		table.insert(array, {
			["Name"] = obj.Name;
			["Pos"] = {
				["X"] = obj.PrimaryPart.CFrame.X;
				["Y"] = obj.PrimaryPart.CFrame.Y;
				["Z"] = obj.PrimaryPart.CFrame.Z;
				["R"] = obj.PrimaryPart.Orientation.Y
				
			}
		)}
	end
end

To load the model in all you need to do is have a place to access the model such as ReplicatedStorage and a basic understanding of DataStore's. Since scripts run top to bottom you can search through the models and check if the name matches the saved one. Then you can give it the position and rotation and anything else you might need. Here is an example of the load system:

if Saved then
	for i, obj in pairs(Saved) do
		if obj then
			local SavedModel = game.ReplicatedStorage.Models:FindFirstChild(obj.Name)
			
			if SavedModel then
				local Model = SavedModel:Clone()
				
				if Model then
					Model:SetPrimaryPartCFrame(CFrame.new(Saved.Pos.X, Saved.Pos.Y, Saved.Pos.Z) * CFrame.Angles(0, math.rad(Saved.Pos.R), 0))
				end
						
				Model.Parent = workspace
			end         
		end  
	end 
else
	Save(plr)      
end

That code will not work but with some editing it would work fine. Thats how I do it. Hope this helps!

11 comments

0

If you want to save decals I suggest making a few parts named DECAL and then find all the parts within the model named DECAL and save those parts too.

0

but how do i save the parts inside it that has new decals (i think you already shown how to do this but im blind so i cant see it)

0

You would have to write a function that loops through the descendants of each model. Next check if the part (in the model) has a decal. If so then save it else move on.

0

Does the script you made loop through replicatedstorage? for example: there are 5 models in rp, does the script you made save all the properties for those models, then clone them?

0

but when i save the decal, its the parent. How do i set the parent, how can i save the location, how can i give the decal its place when every part on the model is named "Part"?

0

Just put decals in every object and save the id's of the decals. then all you need to do is load in the decal id not the whole instance.

0

When I save the models I am not looping through replicated storage but where the model you want to save is located. When I load the model in again then I am looping around replicated storage.

0

how can i save the exact decal if every part is named part? like theres an decal in every part and i wanna save/load a decal for 1 part but every part is named part?

0

Just make a function that loops through the descendants of the model and inserts the decal id into the save table. Then do the inverse to load.

0

Maybe before asking another question research the topic a little more so you at least understand the basics of the concept. I cannot help you out with everything.

0

Maybe before asking another question research the topic a little more so you at least understand the basics of the concept. I cannot help you out with everything.

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