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

How can I select a huge amount of values when saving?

Asked by 4 years ago

Yes, I did use a simulator tutorial script because I'm not good at services.

I'm trying to save a huge chunk of values and I used :GetChildren() and it doesn't work.

I'm trying to find an alternative way to save tons of values without putting tons of functions.

Here is the script:

local DS = game:GetService("DataStoreService"):GetDataStore("StatData")
game.Players.PlayerAdded:Connect(function(plr)
    wait()
    local plrkey = "id_"..plr.userId
    local savevalue = plr.leaderstats.Coins
    local savevalue2 = plr.leaderstats.Gems
    local savevalue3 = plr.leaderstats.Power
    local savevalue4 = plr.Stats.ElementInv:GetChildren()
    local savevalue5 = plr.Stats.PetInv:GetChildren()
    local GetSaved = DS:GetAsync(plrkey)
    if GetSaved then
        for e = 1,#savevalue4 do
            for a = 1,#savevalue5 do
                local save4 = savevalue4[e]
                local save5 = savevalue5[a]
                savevalue.Value = GetSaved[1]
                savevalue2.Value = GetSaved[2]
                savevalue3.Value = GetSaved[3]
                save4.Value = GetSaved[4]
                save5.Value = GetSaved[5]
            end
        end
    else
        for e = 1,#savevalue4 do
            for a = 1,#savevalue5 do
                local save4 = savevalue4[e]
                local save5 = savevalue5[a]
                local NumbersForSaving = {savevalue.Value, savevalue2.Value, savevalue3.Value, save4.Value, save5.Value}
                DS:GetAsync(plrkey, NumbersForSaving)
            end
        end
    end
end)
game.Players.PlayerRemoving:Connect(function(plr)
    local savevalue = plr.leaderstats.Coins
    local savevalue2 = plr.leaderstats.Gems
    local savevalue3 = plr.leaderstats.Power
    local savevalue4 = plr.Stats.ElementInv:GetChildren()
    local savevalue5 = plr.Stats.PetInv:GetChildren()
    for e = 1,#savevalue4 do
        for a = 1,#savevalue5 do
            local save4 = savevalue4[e]
            local save5 = savevalue5[a]
            DS:SetAsync("id_"..plr.userId, {savevalue.Value, savevalue2.Value, savevalue3.Value, save4.Value, save5.Value})
        end
    end
end)

1 answer

Log in to vote
0
Answered by
NeptyU 15
4 years ago
-- Saving
local SaveTable = {}
for i, v in pairs(plr.leaderstats:GetChildren()) do
    table.insert(SaveTable,{v.Name..v.Value})
end

-- Loading

for i, v in pairs(DS:GetAsync("id"..plr.userId)) do
    if plr.leaderstats:FindFirstChild(v[1]) ~= nil then
        plr.leaderstats[v[1]].Value = v[2]
    end
end

Might work im not sure, if it doesn't it kinda gives an idea on how to do it

0
Roblox is down rn. I'll accept your answer if it works. CandyWreckEpicness 115 — 4y
0
Roblox is now back up can you give me more information on where to insert the values and what some of the stuff is supposed to be please? CandyWreckEpicness 115 — 4y
0
Another reminder to give me the instructions of the script. CandyWreckEpicness 115 — 4y
0
Another reminder to give me the instructions of the script. CandyWreckEpicness 115 — 4y
View all comments (13 more)
0
everything between the lines of 1 and 6 goes in the PlayerJoined function. everything below line 8 is for the PlayerLeaving function NeptyU 15 — 4y
0
The leaderstats isn't the problem it's the petinv and elementinv. CandyWreckEpicness 115 — 4y
0
The leaderstats isn't the problem it's the petinv and elementinv. CandyWreckEpicness 115 — 4y
0
Bruh why do my comments keep duplicating? CandyWreckEpicness 115 — 4y
0
Wait I realized I could just put the elementinva and petinv inside the i v thing. CandyWreckEpicness 115 — 4y
0
I need more information on how this works because it isn't functioning. CandyWreckEpicness 115 — 4y
0
I need more information on how this works because it isn't functioning. CandyWreckEpicness 115 — 4y
0
Data stores don't save on PlayerLeave if your in studio, have you tried testing it in the actual roblox game. Sorry fr the late response NeptyU 15 — 4y
0
I have and it doesn't seem to function. I'll try to figure this out on my own since the responses are not fast. CandyWreckEpicness 115 — 4y
0
Ok when I try to save a bool value which is in PetInv and ElementInv it doesn't work because the save system can't do it for some reason. CandyWreckEpicness 115 — 4y
0
Ok when I try to save a bool value which is in PetInv and ElementInv it doesn't work because the save system can't do it for some reason. CandyWreckEpicness 115 — 4y
0
This site needs to fix comment duplication. CandyWreckEpicness 115 — 4y
0
Ok I have set all the bool values into number values so 0 = false and 1 = true but the loading thing does not work. Could you give me more info on just that. Sorry for all the trouble. CandyWreckEpicness 115 — 4y
Ad

Answer this question