Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My inventory system seems flawed, any suggestions on better ways to do it?

So basically I made a game that uses DataStores to save a player's inventory. For example, if they were to buy an object in the game (using in-game currency), it will add a value of 1 to IntValues that are saved to the player. I am using this to save the amount of objects the player has had in previous games, and those objects will be returned to them whenever they rejoin. For example, a player tries to buy an item named "Donut". If they have enough money for it, it gives them "Donut", plus adds the value of 1 to the player's "DonutAmount" value:

game.ReplicatedStorage.buyDonut.OnServerEvent:Connect(function(client) 
	if client.Money.Value >= 5 then 
		client.Money.Value = client.Money.Value - 5
		game.ServerStorage.Donut:Clone().Parent = client.Backpack
		client.DonutAmount.Value = client.DonutAmount.Value + 1
	end
end)

Whenever a player joins, it loads the value they have for "DonutAmount" and makes a for loop that gives them the item for how many of the item they have (for i = 1, DonutAmount do):

local dss = game:GetService("DataStoreService") 
local myDataStore = dss:GetDataStore("myDataStore1")
local DonutAmount = myDataStore:GetAsync(client.UserId.."-DonutAmount") 
for i = 1, DonutAmount do 
	local clone = game.ServerStorage.Donut:Clone
	clone.Parent = client.Backpack
end

The whole reason why I'm asking this question is because I am worried that the game will overload from loading the data, considering this game is going to have tens, if not hundreds, of items to buy.It's already overloaded once with the datastores when only handling 1 item. I do not want to overload the server and cause it to crash. Is there a better method of saving a player's inventory? Could I use separate DataStores to save the player's inventory to, to prevent this?

6 comments

3

table

1

do you think that saving a ton of values like this, even when using a table, could potentially crash the game or cause the datastores to stop working?

1

no

0

ok

0

Ok I have a few things to say 1. it might be a copy-paste error, but on line 5 of the second script :Clone is missing the ()s. 2 pro tip naming is VERY important don't name things like "dss" and such, use the actual name and 3. that script cannon overload, because it gets the DonutAmount from the DataStore only once, so even if DonutAmount was 100000000, it would only retrieve it once 4. ye tables

0

Im recreating the inventory system by trying to save tables to the players for their inventory, and I can't seem to figure out how to save tables to them. Are there table objects (Like "IntValue") in roblox?

1 answer

I Have Also came across issues like like but I found a method for doing this using.. ~~~~~~~~~~~~~~~~~ string.sub("20102923",3,5)

you will find this single line of code to be very helpful in the future

hope I helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.