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

How do I get the Data Store to load the BoolValues?

Asked by 7 years ago

Hello,

I'm having a hard time properly getting my Bool Values to save/load with the Data Store. I have Bool Values in the StarterGui that will turn the Value to true when purchased from the Shop:

hasGun = true hasSword = true etc.

Question: How do I get these to save and reload when the Data Store fires?

Here is my Data Store script that has been worked over several times now:

game.Players.ChildAdded:connect(function(newPlayer)
--Leaderstats Script, IntValues added for Cash, EXP, etc.


    stats.Parent = newPlayer

    local datastore = game:GetService("DataStoreService"):GetDataStore(newPlayer.Name.."Stats")

    local stats = stats:GetChildren()
    for i = 1, #stats do           
        stats[i].Value = datastore:GetAsync(stats[i].Name)
        print("stat number "..i.." has been found")
    end

    local save_interval = 60 * 2 -- every 2 minutes

    wait(save_interval)

    while newPlayer.Parent do
        local stats = newPlayer.leaderstats:GetChildren()
        for i = 1, #stats do           
            datastore:SetAsync(stats[i].Name, stats[i].Value)
            print("stat number "..i.." has been auto-saved")
        end

        wait(save_interval)
    end
end)

game.Players.ChildRemoved:connect(function(oldPlayer)
    local datastore = game:GetService("DataStoreService"):GetDataStore(oldPlayer.Name.."Stats")

    local stats = oldPlayer.leaderstats:GetChildren()
    for i = 1, #stats do           
        datastore:SetAsync(stats[i].Name, stats[i].Value)
        print("stat number "..i.." has been saved")
    end

end)

I've looked at wikis, forums, youtube, I'm just having a really hard time with it, and would appreciate some help. =/ Thanks in advance.

1 answer

Log in to vote
0
Answered by
Glistre -7
7 years ago

not sure but maybe you have to define stats before stats.Parent = newPlayer
local stats = Instance.new("IntValue", stats) stats.Name = "leaderstats" stats.Parent = newPlayer

0
Thanks for the response. :) I already have those defined in my Leaderstats script. All of my stats save/load just fine, its the bool Values for items that I can't get to save. Never2Humble 90 — 7y
Ad

Answer this question