Better way of making an Item/Trail Ownershop System

Hi there, I’m currently making a Item/Trail ownership system in my game, but I’m not sure how to apporach it.

I know I can just make a folder and store all the trails in there, but I was hoping to make a more elegant system. I want it to look more like this:

local TrailTypes = 
		{
			["Blue"] = false,
			["Red"] = false,
			["Green"] = false,
			["Orange"] = false,
			["Purple"] = false,
			["Pink"] = false,
			["Black"] = false,
			["White"] = false,
		}

I tried storing it like a folder on the player but I’m pretty sure that doesn’t work, and just creates a new field in the table

TrailTypes.Parent = Player

How would I do something like this, without using Instance.new("folder)?

This makes no sense. Tables are not instances, Meaning they do not inherit The Parent property, because they are tables that store information, and not Instances.

Heres how you use use them (With using a dictionary, which is a certain type of table):

--Heres how to access one item: 

print(TrailTypes["White"]) 

--or 

print(TrailTypes.White) 

--both print out false; their value

--Heres how to write an item:

TrailTypes["White"] = "ReWritten" 

--or

TrailTypes.White = "ReWritten" 

--When printed like the first method of accessing an item, prints "ReWritten"

--Here is how to access all items at once

for item, value in TrailTypes do 
 print(item, value) 
end

--prints the following: 

Blue false
Red false
Green false
Orange false
Purple false
Pink false
Black false
White false

Let me know if you have any other questions!

I know that, and this doesn’t really solve my problem, because I need to be able to access this table from other local scripts which is why I want to store it on the player

Well then you could turn it into a folder. Your other option is to use Remote Events / Bindable Events / Module scripts and have the Scripts request this information (I am offering this because ik you said you didn’t want a folder, but the most simple route for sharing this info is by, making this a folder; and this folder comes with other perks like you being able to use :GetPropertyChangedSignal() on the values ). If you would like to go this route, let me know (and what type of method), but, simply you could do this, with the methods I showed you above for; “making a folder”:

local Folder = Instance.new("Folder")
Folder.Name = "TrailTypes"
Folder.Parent = player


for item, value in TrailTypes do 
     local BoolenValue = Instance.new("BoolValue")
     BoolenValue.Name = item
     BoolenValue.Value = value
    BoolenValue.Parent = Folder
end
1 Like

Yeah I guess, I’m just going to build my system with folders, but I thought I could make it look better code-wise, thanks for the suggestions

I mean you can do other things. Again as I did mention you could use Remote / Bindable events, or module scripts. For something like a shop system though, Its often common to store them in folders for easy access, and the ability to use :GetPropertyChangedSignal() on those values