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

How can i store models/ is storing models with datastore even possible?

Asked by 6 years ago

i am making a car game. all i need is to know how to store a model to the game. how do i do that? what do i need to do? thanks

0
I'm a bit new to DataStores, but I think you can use use a datastore script with things like for i loops, and use in pairs to see if the key for each player has a value of the same name as your car model. User#22980 0 — 6y
0
use values User#23365 30 — 6y
0
Store the name of the model in the data store. You cannot store userdata in data stores. User#19524 175 — 6y
0
You would store a string and use that string to load the car with the same name, you are welcome greatneil80 2647 — 6y
0
Made an answer! zblox164 531 — 6y

1 answer

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

Very simple solution!

The solution

You would simply save the name of the model then when you need it again just make a clone of the model. To save the position of the model you need to create a dictionary which saves the models coordinates. To save the correct model you need to loop around all the models you want to save and get the names. I will give an example of what I mean by saving names (and getting all the required models), and saving the coordinates below.

Example:

01local DataStoreService = game:GetService("DataStoreService")
02local DataStore = DataStoreService("CarSave") -- could not think of anything else
03 
04local function Load(plr)
05    local key = "plr-"plr.UserId
06 
07    local savedCars
08 
09    local success, err = pcall(function()
10        savedCars = DataStore:GetAsync(key)
11    end)
12 
13    if not success then
14        warn("Failed to read data"..tostring(err))
15        return
View all 87 lines...

This process is called serialization. Serialization is where you take an object and convert it to a string (in this case a table) and save it. Then re-create it when needed. It's quite simple when known and understood but can be hard to grasp (it was for me at least).

You will want to make the cars have PrimaryParts so the script will work.

Here is some info on the topics used in this answer:

  1. DataStoreService

  2. CFrame math

  3. PrimaryParts

  4. SetPrimaryPartCFrame

  5. Table functions

  6. Tables and Dictionarys

  7. Developer Wiki (anything else you might need)

All code is untested but the idea has been used me and another devs sandbox tycoon-ish game and it works fine (This code is not exactly the same though).

You will want to save at these times: When the player leaves, when the player clicks the save button (if you have it), when they purchase something, and every x seconds.

Hope this helps!

0
but the models will have diffrent decals and diffrent colors, is that possible to save witht ath method? ieatandisbaconhair 77 — 6y
0
Just add the decal ID along with the other values. ["IDS"] = DECEL1; DECAL2. zblox164 531 — 6y
Ad

Answer this question