Is there a better way to save 120+ Int Values?

hello, I have this simple data store script and I was wondering if there is a better way to save 120+ Int Values here is the code for saving 1 Int Value

local players = game:GetService("Players")
local dataStore = game:GetService("DataStoreService")
local DataStore1 = dataStore:GetDataStore("DataStore1")

players.PlayerAdded:Connect(function(player)
	local folder = player:WaitForChild("Colors")
	local Tool1= Instance.new("IntValue")
	Tool1.Name = "Tool1"
	Tool1.Parent = folder
	Tool1.Value = DataStore1:GetAsync(player.UserId) or 0
	DataStore1:SetAsync(player.UserId, Tool1.Value)

	Tool1.Changed:Connect(function()
		DataStore1:SetAsync(player.UserId, Tool1.Value)
	end)
end)

Set Table if you meant to set at once.

2 Likes

you can save it in a table like this:

local Table = {
	Cash = 0,
	Rich = false
}

print(Table.Cash)
1 Like

you can sterilize the data.

local function SterelizeInts(arr : {number})
	local sterData = ""
	for _,num in arr do
		sterData ..= num.." "
	end
	returm sterData
end

local function DesterelizeInts(sterData : string)
	return sterData:split(" ")
end

this way you can save all the numbers in one key

1 Like

Firstly, it’s serialize.

Secondly, table.concat exists:

table.concat({1, 53, 28}, " ") --> "1 53 28"
3 Likes

yea thanks, i got used to “sterelize” for some reason. Also i totally forgot table.concat

2 Likes

If the values must be a part of the tool, consider using Instance Attributes (roblox.com). They are a lot faster and more efficient than (for example) IntValues. Only use this if you need to store names etc. to each value.

Generally, it is much better to use a regular table. The problem is it will only be accessible within the script. A very easy way to share this table with other scripts could be to use JSON Format (roblox.com) and store it in a string attribute.

3 Likes