Hello so I want to save a folder that contains bool values with the names of all the weapons the player owns in my game with Data Store 2, however if I have tons of weapons in the future I need a simpler way to create the bool values then doing local WEAPON = Instance.New("BoolValue", folder)
and then naming it for every weapon. So how would I just loop through the data, find the weapons the player owns, and create a boolvalue for it?
Heres my code:
local DSS = require(game.ServerScriptService:WaitForChild("DataModule"))
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local dataKey = "INVENTORY"
DSS.Combine(dataKey, "CREDITS", "WEAPONS", "WEAPON_SKINS", "PLAYER_SKINS")
local playerSkins = SS:WaitForChild("PlayerSkins")
local weaponSkins = SS:WaitForChild("WeaponSkins")
local weapons = SS:WaitForChild("Weapons")
_G.PLAYER = game.Players.PlayerAdded:Wait()
_G.PLAYER.CharacterAdded:Connect(loadInventory())
function loadInventory(UpdatedValue)
setDataTable()
local INV_FOLDER = Instance.new("Folder", _G.PLAYER)
local WEAPON_FOLDER = Instance.new("Folder", INV_FOLDER)
local WEAPON_SKIN_FOLDER = Instance.new("Folder", INV_FOLDER)
local PLAYER_SKIN_FOLDER = Instance.new("Folder", INV_FOLDER)
local CREDITS = Instance.new("IntValue", INV_FOLDER)
INV_FOLDER.Name = "INVENTORY"
WEAPON_FOLDER.Name = "WEAPONS"
WEAPON_FOLDER.Name = "WEAPON_SKINS"
WEAPON_FOLDER.Name = "PLAYER_SKINS"
CREDITS.Name = "CREDITS"
end
function setDataTable()
local UserData = {
WEAPONS = {
["CZ-75"] = false,
["AR-15"] = false
},
WEAPON_SKINS = {
["TEST_CAMO"] = false
},
PLAYER_SKINs = {
["TEST_SKIN"] = false
}
}
return UserData
end