Is this the best way to save data?

hello there

so i have a game slot system where players can create and play different slots. Which save but the way i am saving data just seems to messy and takes up to much data

here’s the code

Slot_1 = {
	["Difficulty"] = "None",
	["SlotName"] = "None",
	["DateCreated"] = "None",
	["JoinCode"] = "None",
	["TotalMoney"] = 0,
	["Day"] = 0,
},
Slot_2 = {
	["Difficulty"] = "None",
	["SlotName"] = "None",
	["DateCreated"] = "None",
	["JoinCode"] = "None",
	["TotalMoney"] = 0,
	["Day"] = 0,
},
Slot_3 = {
	["Difficulty"] = "None",
	["SlotName"] = "None",
	["DateCreated"] = "None",
	["JoinCode"] = "None",
	["TotalMoney"] = 0,
	["Day"] = 0,
},
Slot_4 = {
	["Difficulty"] = "None",
	["SlotName"] = "None",
	["DateCreated"] = "None",
	["JoinCode"] = "None",
	["TotalMoney"] = 0,
	["Day"] = 0,
},
Slot_5 = {
	["Difficulty"] = "None",
	["SlotName"] = "None",
	["DateCreated"] = "None",
	["JoinCode"] = "None",
	["TotalMoney"] = 0,
	["Day"] = 0,
},

I have it like this so i can put all the info on a UI so the players can actually tell which slot is which

but like i said before. It just seems messy, and i am stuck at 5 slots if i want to make more. I have to make another one of these, seems slow and sloppy

This is using profile service BTW

Thanks for reading, hope to see you in the replies :+1:

I would keep a big list of all the slots in your case, where the index of the data is the slot “number.”

So in this case, where there are 5 slots:

local Slots = {
	[1] = {
		['Difficulty'] = 'None',
		['SlotName'] = 'None',
		['DateCreated'] = 'None',
		['JoinCode'] = 'None',
		['TotalMoney'] = 0,
		['Day'] = 0
	},
	[2] = {...},
	[3] = {...},
	[4] = {...},
	[5] = {...}
}

Like this, you can add as many slots as you’d like. By simply using table.insert() and table.remove().

Hopefully, this helps! If you have any more questions, or if I didn’t understand your question correctly, let me know!

1 Like

What would this change? Just make it look cleaner, take up less data. or?

1 Like

he just added numbers as indexes on table

1 Like

In theory, they are the same, except for just one variable. However, it is better practice to keep all your slots in a list, instead of per variable.

This is because you can add however many slots you’d like. Instead of being stuck with the fixed 5 slots, for example.

1 Like

alright then. Ill give it a try, thank you!

1 Like

You can just do something like this

local CurrentSlot = ["Slot_"..SlotNumber]

I don’t understand why you would use something like that, it is bad practice. I don’t think there’s any difference between Slots[n] and Slots['Slot_n'], apart from the fact that it takes an extra step to set or get the slot you want.

You can best use an integer for an index, instead of a string. But if this helps you, it will certainly work, it is just bad practice.