How to check when new Instance Data was Added

Hi i would like to know how to check when new data is added, I made a datastore that checks if a key is valid and if it is then load the data, But since the system is set like that New instances i add are always set to 0 heres an example

	for _, values in pairs(playervalues:GetChildren()) do
		data = values
	local success, ret = pcall(Datastore.GetAsync, Datastore, key)
	if success then
		if ret then
			playervalues[data.Name].Value = ret[data.Name]
			playervalues[data.Name].Value = default[data.Name]

This works and loads all the data in, But if i make a new instance, Boolvalue i have to change the DatastoreKey for the values to be set, Does anyone know a way around this.

I’m not entirely sure what you’re asking about, but I’m assuming the problem you’re having is that you are saving a lot of different values onto a bunch of different key values. If this is the problem you are having, you can actually save tables to datastores, which can make data reading and writing faster and handling data easier as well. It works the same way as normal datastores, but there are some datatypes that you can’t save as well incase that becomes a problem such as Color3s, EnumItems, etc.

You can read more about datastores and datasaving below:

Datastore Article

I hope this helps!

Just use the ChildAdded & DescendantAdded events which are fired every time an instance receives a new child/descendant respectively.

So like lets say i have Instances like Cash and Level already and the player has Data for cash and level, But if i add something like gems or EXP later it doesnt load the default values cause theres already a data key assigned

if ret then
		playervalues[data.Name].Value = ret[data.Name] -- NOT NEW PLAYER LOAD key[data]
		playervalues[data.Name].Value = default[data.Name] -- NEW PLAYER ASSIGN DEF VAL

this code is saying if data exist then load in data, But if i make new Instances it wont assign any data cause data[‘new instance’] is nil, hope this makes a brief explanation.