✓ Accepted answer
I'm not exactly sure what your intentions were with this script but:
First of all you cannot save a table. You will have to use the JSON format. Also you try to compare a boot value to 1. Third you never actually load any value.
Your script:
game.Players.PlayerAdded:connect(function(player)
local store = game:GetService("DataStoreService"):GetDataStore("awesomedata")
local key="user_"..player.userId
local BV = Instance.new("BoolValue",player)
BV.Name = "lol"
BV.Value = store:GetAsync(key) or false
BV.Changed:connect(function()
store:SetAsync(key,BV.Value)
end)
end)
Your script saving multiple values using JSON.
local Utils = LoadLibrary("RbxUtility")
game.Players.PlayerAdded:connect(function(player)
local store = game:GetService("DataStoreService"):GetDataStore("awesomedata")
local key="user_"..player.userId
local BV = Instance.new("BoolValue",player)
BV.Name = "lol"
local BV2= Instance.new("BoolValue",player)
BV2.Name = "lol2"
Save = store:GetAsync(key) and Utils.DecodeJSON(GetAsync(Key))
if Save then
BV.Value = Save[1]
BV2.Value = Save[2]
else
BV.Value = true
BV2.Value = false
end
function SaveValue()
store:SetAsync(key,EncodeJSON({BV.Value;BV2.Value}))
end
BV.Changed:connect(SaveValue)
BV2.Changed:connect(SaveValue)
end)
An automatic DataStore script.
local Data = {
["Bool Value 1"] = {"BoolValue"; true};
["Points"] = {"IntValue"; 100};
}
local DataStoreService = Game:GetService("DataStoreService")
Game.Players.PlayerAdded:connect(function(Player)
local UserId = Player.userId
local Folder = Instance.new("Folder",player)
Folder.Name = "Stats"
for Name,Info in pairs(Data) do
local Type, Default = unpack(Info)
local Store = DataStoreService:GetDataStore(Name)
local Stat = instance.new(Type,Folder)
Stat.Name = Name
local Save = Store:GetAsync(UserId)
Stat.Value = Save or Default
Stat.Changed:connect(function()
Store:SetAsync(UserId,Stat.Value)
end)
end
end)