How do you make a auto save part

I know it has to do something with DataStore. im trying to make it so when a player buys something a part gose invisible but only for that 1 person that bot it, i want it so save so its there like everyday even when they leave and get back on
thanks so much for helping,
ive been trying to search it up for so long like about a week and ive gotten almost no were
thanks for reading

Well, unfortunately you can’t save instances with DataStores, and DataPersistence is deprecated so I wouldn’t recommend that either. So either, each part has a unique name, or you create some sort of identifier for every part, either with a StringValue or something in each part so you know how to locate em’.

From there, when the player buys something, you can store the according part’s name in a table, stored server-sided, like so:

local items = {
["Brick1"] = true; --//Brick1 has been bought
}

When a player joins the game, you can use a Remote Event to pass their DataStore information to their client, then they can make all their bought items turn invisible in the game world; for only their client.

This should be a starting point for you. Hopefully it helps, there might also be a better way to go about it but this is what I would probably do. :slight_smile:

3 Likes

i dont get it, can you like tell me a better understanding

ill show you what i mean,

image
like what im i ment to do now do i just typ what you told me to typ inside of the local script?

Responding to the question in the title:

You don’t, because only strings can be saved to DataStores in Roblox (tables automatically being JSONEncoded for that) and data persistence is very unreliable and deprecated as well.

Just do what sharper said, but don’t just type in the pseudo-code in his post there.

Try to:

Save all unlocked places for a player,

{
   ["Newb area"] = true;
   ["part"] = true;
}

add a new key each time a part is bought, and when the player leaves, save the table with the part’s name.
When the player joins, retrieve the owned parts’ names and add them to a cache on the server and each time you need to check whether a player owns one, check in that cache.
By default set all parts to CanCollide = true and Transparency = 0,

-- example of what the cache part would look like
local cache =
{
    ["example player"] = {
                            ["Part1"] = true;
                         },
} -- contains previous data for player

if not cache[player.Name]["Part2"] then  -- to check whether a certain part is owned
   print("player does not own part")
end

-- to let a player own a part
if cache[player.Name]["Part1"] then 
   print("You own the part")
   -- let player access the part, by turning it invisible and with CanCollide set to false
end
2 Likes

you just blew my mined, im super stupid IDK what that dose, like i can read scripts like to see what they do but, i have not even the slightest clue what this one dose, also, what script do i put it into and were?

You don’t put it anywhere because it’s only exemplar.

You need a server-script to access DataStoreService so use that, and for the parts, try to just save owned parts (through any mechanism you verify a part is bought) in the form of a dictionary and when a player joins retrieve data and see whether a certain part is owned when you need to verify, such as by storing retrieved data in a module in pure form and on certain parts being touched, verifying a part’s ownership through the module.

http://lua-users.org/wiki/TablesTutorial

This is wrapper easy to get used to :
How to use DataStore2 - Data Store caching and data loss prevention