How would I go about making a fully saving inventory

Hello, I want to make a saving Sword and player Character thing. So when the play logs back on the game they keep what they bought. Example arsenals equipping place. I want to make it so the player can equip which I should know how to do but then save and be able to access all that bought. This may be confusing but I just want to figure out how to save models and what not. So players can equip them. Thanks.

1 Like

you can put it all into a 2d array. the main array for to store only the arrays for each object. what you can do is to give each object an object_id, as to save on characters. i doubt it will go beyond 999, where as an string could get very long for each item. you can also put the amount in the second array as a second value, and more if you need it. Now you’ve got every item defined and inside of a massive array. after that it’s just about giving each adress a place within the UI. you can also have it be a 3d array, and instead of it being one main array, you can have the Xaxis as the main, the Yaxis inside of the main, and each object inside of the Yarrays.

1 Like

Is there a easier way? I think what I can do is for the swords since there tools is to just save there backpack so when they join they still have there backpack for there for I can disable backpack UI make my own and do it that way but with the characters I have no idea. Ive never used 2d arrays or any of those before so im a little stuck.

the big thing is that it’s really dependant on what you want. i’d reccomend you to assign each object an object_id, and to use arrays if it’s a big inventory. otherwise you can get away with simply making seperate values for every variable without the need for an array

the easiest way is to simply assign every signle part of the player’s inventory a seperate value, but it will very quickly get out of hand after 5/10 items. for “mass storage” on roblox you’ll need to use arrays, or use other constant values, like the math.noise. but since a player’s inventory should not use a noisemap, you’ll have to make an array.

about arrays, combining them with for loops makes a very strong combo. as you can have the for loop, loop though every adress in the array

local Array = {3,4.5,8,"hello",true,7}
print(Array[1],"A") --adress number 1, in this case it's 3
print(#Array,"B") --amount of adresses in the array, in this case 6
for i = 1,#Array do
print(i,Array[i],"C")
end
print("----------")
for i,CurrentAdress in ipairs(Array) do
print(i,CurrentAdress,"D")
end

this should be arrays with for loops basically summed up.

I still dont really get it.Theres just do much going on.

would my tutorial be of help?

5 Likes

just experiment with it for a second. that’s the best way to learn this sort of stuff. also, here’s the api refence for arrays. also known as tables .

2 Likes

As some people mentioned, I think you should use a table. You can have a script that saves the instance (or an item id) in a table in an order, or save that position empty if there is no item. You can then load the items in the correct order and placement.

you can probably learn the Datastore service your self.

or you can use a premade module like the one below

and there is also modules like this other one below. they’ll help you create container GUI (like inventories and shops)

Personally, i wouldn’t reccomend pre made assets. They’ll always break in some way, and because you didn’t program it, you’ll have no clue how to fix it for surely another 20 mins to multiple days for larger scripts.

In your code local tool = tool[name] I have a error where it cant get the sword. I think the reason the tool hasent been specified? If you can just help me with that.

If it’s created on the client, only the client will be able to see it. You might need to use a remoteevent from the client to the server.
But this is the EXACT reason why one should not use pre made assets.

wait what? What is this towards? The error is only on the server.

If the sword only exists in a player’s client, the server won’t be able to see it. This is why you’ll need an remote event, as to send the objectvalue of that sword so it can be replicated on the server, or if you only need to have it’s name, you can simply only send it’s name.

yes thats what I have. If the players cash is greater then 100 then delete 100 then fires a remote event. ohhh I should delete the cash on server

I doubt that will fix it, as now the value ‘cash’ will not exist on both the client and the server. The simplest fix is to make the saving system by yourselve. This way you’ll know what can and can’t go wrong, and it will be the most efficient for your game.

Are datastores broken? Non of my data stores are working correctly. Like my currency aint saving

Datastores were indeed broken last week, but they should be fine again. I can’t really help you much further though, as i have no clue on what’s inside of your scripts and how the game works.
Just follow the cycle of: make → fail → debug → repeat, until it works.
The api reference is your best friend in this case.

1 Like