How can I save this table data? I can do databases but I never done them using tables

local NPC_Data = {
	['Money'] = 0,
	['NPCs'] = {
		[1] = {
			['Rank'] = 'Private',
			['Lvl'] = 1,
			['XP'] = 0,
			['XPN'] = 100
		},
		[2] = {
			['Rank'] = 'Sergeant',
			['Lvl'] = 1,
			['XP'] = 0,
			['XPN'] = 100
		},
	}
}

This is the sort of data I need to save and load every time a player leaves and joins a server, but I am also questioning, if I add more data to that table, for example like this…

function AddNpc(Npc, rank)
	local Last = NPC_Data['NPCs'][#NPC_Data['NPCs']]
	NPC_Data['NPCs'][#NPC_Data['NPCs'] + 1] = {
		['Rank'] = rank,
		['Lvl'] = 1,
		['XP'] = 0,
		['XPN'] = 100
		
}

end

Would this still be salvable or the datastore would just ignore it completely and just save the 2 initial datas in the table?
I figured out how to load the data from the table into the NPC themselves, but i just need some help in saving it and loading it.

1 Like

You can use HTTPService’s JSON encode and decode functions to turn your table into a JSON string and back into a table for saving and loading it.

1 Like

Thank you so much! I really appreciate your help!

1 Like

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