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

How can i save models with DataStore? [closed]

Asked by 6 years ago

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

0
I believe it is impossible to save models in the data store yHasteeD 1819 — 6y
0
Try to make a datastore using the model and getting the children of the model. CaptainD_veloper 290 — 6y
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. User#25115 0 — 6y
0
How much datastore do i need? (getdatastore). Do i need one or a ton? jdm4llfem8 94 — 6y
View all comments (3 more)
0
also what do you mean by converting it back? do i need to do Instance.new? jdm4llfem8 94 — 6y
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. User#25115 0 — 6y
0
what do i need to "setasync"? there are too many parts, so how do i get the correct table? jdm4llfem8 94 — 6y

Closed as Not Constructive by Void_Frost, zblox164, DeceptiveCaster, and evaera

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
zblox164 531 Moderation Voter
6 years ago
Edited 6 years ago

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 PrimaryPartsbefore 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 ReplicatedStorageand 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!

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. zblox164 531 — 6y
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) jdm4llfem8 94 — 6y
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. zblox164 531 — 6y
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? jdm4llfem8 94 — 6y
View all comments (7 more)
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"? jdm4llfem8 94 — 6y
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. zblox164 531 — 6y
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. zblox164 531 — 6y
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? jdm4llfem8 94 — 6y
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. zblox164 531 — 6y
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. zblox164 531 — 6y
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. zblox164 531 — 6y
Ad