Question about tables

Hello,

(This is an example)
Let’s say I have a folder inside ServerStorage with parts that have properties, like this:
image

This player can spawn these parts via a GUI, which will clone the selected part and give it the saved properties.
How can I make a table of the properties to save so that each player have their saved values inside the part that they spawn when they join back in?

Is it possible to make something like this, for each player. Basically something that loops through all the parts in serverStorage, add thems in a table like that “as an index” and saves its properties:

local table = {
	
	["Part1"] = {
		points = 1;
		active = false;
	},
	
	["Part2"] = {
		points = 3;
		active = false;
	},
	
	["Part3"] = {
		points = 5;
		active = true;
	},
}

I’m kind of having a hard time explaining this lol, if you need clarification just ask.

Yes, when the player is added you can have a sort of cache for the data where you load it if it isnt there and if it is there then you set the cache to the new data and then you can retrieve the data throughout the game and then when the player leaves you can just save that data pretty easy by just indexing their userid with whereever you put the cache and then making sure to remove the player’s cache after you have saved their data

1 Like

Yes, I do know how to use datastore and saving tables. Maybe my question wasn’t too clear: how can I actually “make” one table with that “structure” ?

1 Like

What do you mean make that table with that structure you already did it in your original post im confused what your asking, like how to make it so that it’s unique to the player?

local cache = {}

game.Players.PlayerAdded:Connect(function(player)
	cache[player.UserId] = {
		["Part1"] = {
			points = 1;
			active = false;
		},
		
		["Part2"] = {
			points = 3;
			active = false;
		},
		
		["Part3"] = {
			points = 5;
			active = true;
		},
	}
end)

1 Like

Nope, like if I make a table I do

local table = {}

If I want to add some data I do

table.insert(table, data) or table[i] = data

I am asking how could I create a table for each player, that gets ever part in the ServerStorage folder and creates and index with their names and makes “arguments” in it, like this:

["Part1"] = {
     Points = 1;
     Active = false;
},

etc…

Yes on the line of this, but making a for loop that loops through the folder in ServerStorage and makes “indexes” with the items names in the ServerStorage folder

This looks like what I needed, I will check it right now. Thank you!

Edit: had to change some stuff inside the Module to make it fit to my needs, but it works nicely! Thank you

1 Like

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