Heyo, I’m looking to create a shop system but I’m unable to figure out a way to do it effectively. The issue is that this way of creating a shop will work when there’s only a few items in the shop but it becomes tedious when I want to create shops with large amounts of items.
My inefficient way of creating shops:
Create a folder in Players.player called “Items”
In the items folder I insert BoolValues
Set the BoolValue names to the name of the item I want to give the player
I then create a shop manager script that gives the player the item if the apple BoolValue is set to true
Example: The player buys an apple > I then set Players.Playername.Items.Apple.Value = true > The shop manager script notices that the apple BoolValue is now set to true and gives the player an apple
My reasoning for this: It’s the only way I know how to use a DataStore to save the player’s bought items.
This probably sounds silly but keep in mind that I’m a novice scripter and have very little experience with creating shops. Hopefully someone of you that are more experienced than I am can give tips/point me to resources on creating more efficient shop systems.
(Sorry for the awkward layout and not providing code examples I’m on mobile)
There are many ways you can do this, the one I use is creating a value for every item. This means I can have 2 apples, and have 1 be a bit different without messing up everything. Saving it would just be going through all the items and adding them to a table and saving that table. Easy.
Another way would be to just use tables without any objects, when you want to give a player an item you add it to the table and send a remote from the server to the player telling it to update its inventory. Then you’d also have a remote for getting the inventory. For saving you’d simply just save the table.
So the second idea is just if you hate using objects, but it’s a bit more time-consuming.
You should probably be using a module script to handle inventory related functions and another module script to handle purchases. The purchase module script should invoke a function in the inventory module to add the item to the player. You should have another module script in replicated storage that keeps all of your item data organized in a table, with names, prices, descriptions, thumbnails, etc. Your client side shop code should loop through this table to display the items, then use a remote function to invoke the server with the name of the item to buy. The server then check if the player has enough money by indexing the item table and if they do, it invokes the inventory module to add the item. I would provide some code but on mobile. This is the general idea you should be working with for this kind of system.