I’m trying to make a Inventory system and I want to save player’s inventory. There will be IntValues inside the Inventory folder thats inside the player and I want them to get saved with their Attributes. It sometimes saves but it only saves one IntValue. The others doesnt get saved.
I’m trying to save these
Player Added:
local fishData = data:GetAsync(Player.UserId)
if fishData ~= nil then
for i, v in pairs(fishData) do
if FishFolder:FindFirstChild(v) then --and inventory:FindFirstChild(v) == nil then
FishFolder[v]:Clone().Parent = inventory
end
end
end
Player Removing:
local FishTable = {}
for i, v in pairs(Player.Inventory:GetChildren()) do
table.insert(FishTable, v.Name)
end
if FishTable ~= nil then
data:SetAsync(Player.UserId, FishTable)
end
I know how to save values etc. Right now I’m trying to save an inventory, like theres a fish backpack and i want to save the backpack for everytime player joins. And the backpack is a folder, the fish is a IntValue. Fish has attributes inside it like Rarity and Price
local DataStoreService = game:GetService("DataStoreService")
local FishDataStore = DataStoreService:GetDataStore("FishBackpack")
-- Save the player's fish backpack data when they leave the game
game.Players.PlayerRemoving:Connect(function(player)
local fishBackpack = player:FindFirstChild("FishBackpack")
if fishBackpack then
local fishData = {}
for _, fish in pairs(fishBackpack:GetChildren()) do
if fish:IsA("IntValue") then
table.insert(fishData, {
Name = fish.Name,
Value = fish.Value,
Rarity = fish:GetAttribute("Rarity"),
Price = fish:GetAttribute("Price")
})
end
end
FishDataStore:SetAsync(player.UserId, fishData)
end
end)
-- Load the player's fish backpack data when they join the game
game.Players.PlayerAdded:Connect(function(player)
local fishData = FishDataStore:GetAsync(player.UserId)
if fishData then
local fishBackpack = Instance.new("Folder")
fishBackpack.Name = "FishBackpack"
fishBackpack.Parent = player
for _, data in pairs(fishData) do
local fish = Instance.new("IntValue")
fish.Name = data.Name
fish.Value = data.Value
fish:SetAttribute("Rarity", data.Rarity)
fish:SetAttribute("Price", data.Price)
fish.Parent = fishBackpack
end
end
end)