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

How to Make this script to save 2 bool values and create?

Asked by 5 years ago

**How to Make this script to save 2 bool values and create? **

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("BoolSave")

game.Players.PlayerAdded:connect(function(player)
 local folder = Instance.new("Folder",player)
 folder.Name = "stats"
 local bool = Instance.new("BoolValue",folder)
 bool.Name = "BoolValue"

 bool.Value = ds:GetAsync(player.UserId) or false
 ds:SetAsync(player.UserId, bool.Value)
end)


game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.stats.BoolValue.Value)
end)
0
use tables, instead of for example bool.Value make it {bool.Value, bool2.Value}, to access, it simply do Bool1 = Saved[1] Bool2 = Saved[2] (or something like that) User#20388 0 — 5y
0
i tried its dont works User#21499 0 — 5y

1 answer

Log in to vote
0
Answered by
PropzFx 27
5 years ago

Instead of using game.Players.PlayerRemoving you should use bool.Change

if i have understood you correctly you want to save 2 values like this:

local ds1 = game:GetService("DataStoreService"):GetDataStore("BoolSave")
local ds2 = game:GetService("DataStoreService"):GetDataStore("BoolSave")

game.Players.PlayerAdded:Connect(function(player)
    local stats = Instance.new("Folder", player)
    stats.Name = "Stats"

    local bool1 = Instance.new("BoolValue", player)
    bool1.Name = "BoolValue1"
    bool1.Value = ds1:GetAsync(player.UserId) or false

    local bool2 = Instance.new("BoolValue", player)
    bool2.Name = "BoolValue2"
    bool2.Value = ds2:GetAsync(player.UserId) or false

    bool1.Changed:Connect(function()
        bool1:SetAsync(player.UserId, bool1.Value)

    end)

    bool2.Changed:Connect(function()
        bool2:SetAsync(player.UserId, bool2.Value)

    end)

end)
Ad

Answer this question