How can I organize in-game shops for programming?

Hello all. Tonight I was tasked with creating an in-game shop UI and I’m also responsible for scripting it. This system will use a combination of asset IDs and dev product IDs and I was curious as to how others would set this up.

The issue I’m facing is, how can I program this with expansion in mind. For example, I could just go and create a folder under the server script for the shop, and include asset ID’s with attributes, or I could create values in folders under the script. One thing that’s important to me is maintaining the same loading order each time which isn’t really reliable if I use values as things in Explorer are ordered alphabetically. I’ve thought of using attributes, but if you want to order those you’d need to shift each one down. Another solution I’ve thought of is simply writing into the script, but at the same time, I feel this could get complicated fast.

The reason I look for these abilities is because I’m attempting to have each “frame” (Passes, Items, and buy coins) to load with it’s appropriate selections, but due to them needing to be ordered and each frame holding different types of store items it’s hard for me to come up with a solution.

If anyone has any insight, it’d be greatly appreciated, especially for the future.

1 Like

What I have done for previous projects is to first, create a dictionary on the server with all the necessary shop info, things like price, name, display order, etc, and send it to the player when they join.

On the client, they can use the data retrieved from the server to create item cells and customize them as needed using the relevant prices, display order, and name. This makes it easier for you to handle events like buying items, inventories, etc.

2 Likes

Thanks for the advice! I suppose I’ll write it into the script and have it edit-able from there

1 Like

Here’s an example of a dictionary you would put on the server: (just an example, code could be improved)

--//Services
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local ShopInfo = ReplicatedStorage.ShopInfo

--//Tables
local ShopInfo = {
	RocketLauncher = {
		DisplayOrder = 1,
		Price = 100,
	},
	
	MagicCarpet = {
		DisplayOrder = 2,
		Price = 300,
	}
}

--//Functions
Players.PlayerAdded:Connect(function(player)
	local playerShopData = DataStoreService:GetDataStore(player) or {}
	
	--//Ability to send ShopInfo and player's shop data if needed
	ShopInfo:FireClient(player, ShopInfo, playerShopData)
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.