how do i make tools save across places? i am a beginner scripter, and i am making a game with two places, and in the starter place, there is an item shop, whereas in the main place, there is not. ive already made saving leaderstats with datastores, so i tried using a similar strategy to make this work, but it did not work. i have no idea how to do this
The question is how you want to represent the data of tools. Basically, you can convert the tools to a storable piece of information, like an array of strings, that you can then load and convert back into tools on the other place.
If all the tools have different names then you can just store their names as an array inside your player data. For example:
local playerData = {
Coins = 50,
Gems = 100,
Tools = {"Pickaxe", "Axe", "Scythe", "Shovel"},
Pets = {},
--etc.
}
Then you can have a copy of the tools on the other place, in server storage, and copy them from there according to the names stored in player data. Like this:
--you should run this on every character respawn
for _, name in pairs(playerData.Tools) do
game.ServerStorage.Tools[name]:Clone().Parent = player.Backpack
end
I use ProfileService to load my tools by checking if I have the item in the table and if so I’ll clone the item from ReplicatedStorage (yes it’s replicatedstorage for a reason) and put it on my inventory and yes, it also saves your data across places. The only difference from the normal DataStore is that it uses tables to store and save data instead of using values like StringValues, NumberValues etc.
my bad, i forgot to mention that, in the shop, there is an equip button that you can click, and only then would the specific tool you equipped go in your inventory, or, backpack. this doesnt look like it would work in that scenario, i can try however
The normal datastore also only stores tables and things like numbers, booleans, and strings. The reason you think it stores instances is that you haven’t noticed all these scripts do something like Cash.Value
when making the API call to the datastore, and therefore only save the data, not the instance. Instances can’t be saved in data stores directly, that’s why serialization libraries exist that basically use sophisticated ways to convert instances to strings.
The reason only basic forms of data are allowed like numbers, strings, booleans, and tables is because Roblox datastores save the data as JSON-encoded strings.
Whoops, my apologies. I completely forgot that DataStore also stores values in a table, but what’s cool about ProfileService is that you won’t even have to worry about data losses, or server crashes resulting in data losses.
im a bit confused on this. i dont think a table would save from one script to another in a different place. again, im a beginner scripter, so i dont really understand how to do this
ProfileService DOES save across places, I have tested it once. Of course you can always look up tutorials on youtube like https://www.youtube.com/watch?v=qX62XC6SUKg&t=364s&pp=ygUgaG93IHRvIHVzZSBwcm9maWxlZXNydmljZSByb2Jsb3g%3D&ab_channel=MonzterDEV which I used.
A solution is to make an inventory UI on the other place(or the main one as well) that has all the bought shop items but doesn’t let you buy new ones(as all inventories). Then you just need to store the tools in ServerStorage
as I showed you, add an equip button for each one of them in the inventory, and when its clicked, copy a tool to the player backpack. Also you can have a datastore array that stores the currently equipped tools, so tools don’t unequip between places.
tried it, but it didnt work and just left me extremely confused. i had no idea what they were doing nor what they were talking about so i have no idea how to fix it
He should have an open source game in the comments of the video, that’s also where I had to take the scripts because the video was confusing me aswell.
You can read this article for more information
ok, but how would i update the inventory ui when the player buys something? im a bit confused
I do this using boolvalues and renaming them to the item, then run a for loop to check for any new boolvalue that has been added to my folder and when the boolvalue’s name matches the item I just bought, then I’ll clone the item and parent it to player’s inventory.
i found the game, but it just made my computer crash. when i reopened my computer, the game was nowhere to be found, not even in the desc of the video. weird, but yeah, i cant use it
I guess you should just stick to DataStore then
ive been watching tutorials for several hours and every single one of them appears to be outdated. help
nvm i just had to test it in the actual game lol im silly
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.