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

how would i save multiple items in a folder?

Asked by
MHaven1 159
5 years ago
Edited 5 years ago
function getitems(plr)
    local holder = game.ReplicatedStorage:FindFirstChild(plr.Name.."'s Items Holder"):GetChildren()
    for i,v in pairs(holder) do
        if v.ClassName == "StringValue" then
            if v.Name ~= "Value" and v.Value ~= "" then
                local id = game.Players:FindFirstChild(plr.Name).userId
                itemDataStore:SetAsync(id..":items", v.Value)
            end
        end
    end
end
    local getitems = itemDataStore:GetAsync(newplayer.userId..":items")
    if getitems == nil then
        print(newplayer.." Has No Items!")
    else
        local newitem = Instance.new("StringValue")
        newitem.Name = getitems
        newitemValue = getitems
        newitem.Parent = game.ReplicatedStorage:FindFirstChild(newplayer.Name.."'s Items Holder")
    end

im trying to save multiple values in a folder in replicated storage but this current script only saves 1 of those values not all of them. im pretty new to datastore and scripting in general. any help appreciated TY.

0
You could store the values in a dictionary, with the index being the value's name and value being the actual value. An example being {["Cash"] = 100, ["Level"] = 5}. Once you have the dictionary created, save it to the Datastore. NOTE: You may have to use JSON Encoding/Decoding for the dictionary. PreciseLogic 271 — 5y

1 answer

Log in to vote
1
Answered by
T1mes 230 Moderation Voter
5 years ago

You're trying to save each item individually which is overwriting it each time

Instead you should be putting all of the strings into a table and then save the table

when you load the table, simply loop through it and put it back into the folder

0
yea idk how to put all the stings into a table and save the table lol. ama try searching it up on wiki or something when im on tomorrow. ty for the help MHaven1 159 — 5y
0
Thanks it helped me alot learned how to work with tables and everything and now it works. MHaven1 159 — 5y
Ad

Answer this question