Datastore doesnt work

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
image

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

read documentation Saving Data | Documentation - Roblox Creator Hub

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)

what? post deleted by author please dont ghost ping me

i tried the code youve sent then realised i wrote something wrong but it still doesnt work

The problem was in studio, when I tried to test it in Roblox player it worked :smile:

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