Hello,
I have a problem. My DataStore has way more than 200 variables. Each variable corresponds to a BoolValue. These BoolValues, 720 of them to be exact, are what makes my custom Inventory system work. However, as there is a 200 variable limit, I'm at a loss for how to keep these in a single DataStore script.
I could split them up into multiple scripts, but would that cause a problem? Or, can I set up multiple save functions within the DataStore?
For example:
function loadToolData1(Player)
-- variables 1-199
function loadToolData2(Player)
-- variables 200-399
function saveToolData1(Player)
-- variables 1-199
function saveToolData2(Player)
-- variables 200-399
etc?
Here is how my DataStore is currently set up, but abridged to show just one variable and the Coins.Value from the leaderstats. The error I receive is: Error: "function at line 9 has more than 200 local variables"
local module = {}
local DataStoreService = game:GetService("DataStoreService")
local InventoryItems = DataStoreService:GetDataStore("XXXXXXX")
local ToolGiverCheck = require(script.ToolGiverCheck)
AUTOSAVE_INTERVAL = 120
function loadToolData(Player) --The line where the error pops up.
local Key = "PlayerIdNum-"..Player.UserId.."_ToolItems"
local DataToGet = InventoryItems:GetAsync(Key)
local InvData = Player:WaitForChild("Inventory")
local HasM9 = InvData:WaitForChild("HasM9")
local ls = Player:WaitForChild("leaderstats")
local coins = ls:WaitForChild("Coins")
if DataToGet == nil then return end
HasM9.Value = DataToGet[1] == 1
coins.Value = DataToGet[14]
print("Data successfully loaded for "..Player.Name)
end
function saveToolData(Player)
local Key = "PlayerIdNum-"..Player.UserId.."_ToolItems"
local InvData = Player:WaitForChild("Inventory")
local HasM9 = InvData:WaitForChild("HasM9")
local ls = Player:WaitForChild("leaderstats")
local coins = ls:WaitForChild("Coins")
local DataToSave = {}
if HasM9.Value == true then table.insert(DataToSave, 1) else table.insert(DataToSave, 0)
table.insert(DataToSave, coins.Value)
InventoryItems:SetAsync(Key, DataToSave)
print("Data successfully saved for "..Player.Name)
end
game.Players.PlayerAdded:Connect(function(Player)
local Key = "PlayerIdNum-"..Player.UserId.."_ToolItems"
--remove createdata and get data functions
-- TOOLS
local tnew = Instance.new
local ts = tnew("Folder")
ts.Name = "Inventory"
ts.Parent = Player
local tool1 = tnew("BoolValue")
tool1.Name = "HasM9"
tool1.Value = false
tool1.Parent = ts
--leaderstats
local inew = Instance.new
local ls = inew("Folder")
ls.Name = "leaderstats"
ls.Parent = Player
local coins = inew("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = ls
loadToolData(Player)
repeat wait() until Player.Character
if Player.Character and Player.Character:FindFirstChild("Humanoid") then
Player.Character.Humanoid.MaxHealth = 100 + (level.Value*10)
end
level.Changed:Connect(function(value)
if Player.Character and Player.Character:FindFirstChild("Humanoid") then
Player.Character.Humanoid.MaxHealth = 100 + (level.Value*10)
end
end)
Player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").MaxHealth = 100 + (level.Value*10)
ToolGiverCheck.giveTools(Player)
end)
local required = (level.Value*70)
experience.Changed:Connect(function()
if experience.Value >= required then
level.Value=level.Value+1
experience.Value = experience.Value-required
end
end)
ToolGiverCheck.giveTools(Player)
end)
-- PLAYER REMOVING
game.Players.PlayerRemoving:Connect(function(Player)
saveToolData(Player)
end)
spawn(function()
while wait(AUTOSAVE_INTERVAL) do
for i, Player in pairs (game:GetService("Players"):GetChildren()) do --for every player in the game, save
print("Auto-saving " .. Player.Name .. "'s Data")
saveToolData(Player)
print("Successfully Auto-saved " .. Player.Name .. "'s Data")
end
end
end)
return module

2 comments
I mean, you can try. As long as you load all the datastores that you saved when player joins. For example, "DataStore1" saves from 1-200, "DataStore2" saves from 200-400, and so on.
I would try something with local Key = "PlayerIdNum-"..Player.UserId.."_ToolItems_1" and change the _1 to _2 and _3 and _4 and _5 for each data section