Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would you save a data store without listing it?

Asked by 8 years ago

I'm trying to make an inventory, and i'm planning on adding more items, but I want it easier to do. I'm planning to add more items soon enough. I'm trying to make a table, so it reads the list of items values that is put somewhere, and copy those values to the player and still be able to save those values

ATTEMPT

local DSService = game:GetService('DataStoreService'):GetDataStore('HLLegendsInvServicetesta')
local ITEMService = game.ReplicatedStorage.CONFIG.Items
var = nil
game.Players.PlayerAdded:connect(function(plr)

    local inv = Instance.new('Model', plr)
    inv.Name = 'minventory'
    for _, v in pairs(ITEMService:GetChildren()) do
        if v:IsA('IntValue') then
            var = v:Clone()
            var.Parent = inv
            var.Name = v.Name
        end
    end

    local key = 'id'..plr.userId

    local savedvalues = DSService:GetAsync(key)

    if savedvalues then
        for _,v in pairs() do
            if v:IsA('IntValue') then
                 -- then I just gave up on this line.......
                -- it was supposed to save the values above, or set them to a save number....
            end
        end
    else
        local vts = {
            Tin.Value, 
            Iron.Value, 
            Tungsten.Value,  -- ignore these lists
            Meteorite.Value, 
            Lead.Value, 
            Copper.Value, 
            Granite.Value, 
            Steel.Value, 
            Gold.Value, 
            Diamond.Value
            }
        DSService:SetAsync(key, vts)
    end
end)

Read this if it helps
ITEMS LOCATION IF IT HELPS

game.Players.PlayerRemoving:connect(function(plr) -- Just if it helps doe
    local key = 'id'..plr.userId
    local items = plr.minventory
    local vts = {
        items.Tin.Value,
        items.Iron.Value,
        items.Tungsten.Value,
        items.Meteorite.Value,
        items.Lead.Value, -- ignore lists
        items.Copper.Value,
        items.Granite.Value,
        items.Steel.Value,
        items.Gold.Value,
        items.Diamond.Value
        }
    DSService:SetAsync(key, vts)
end)

I just kinda gave up on it since it's soo hard for my head. Sorry for a long question, i'm trying to make it as understandable as possible

1
Please make your scripts shorter and more effective first please... Avectus 120 — 8y
1
Don't forget to pre load the assets! Lem0nzzx 70 — 8y

Answer this question