Hello guys, I’m working on a game and I wanna use data store 2. I’m experimenting with data store 2 and I made this script
local ds2 = require(game.ServerScriptService.DataStore2)
ds2.Combine("Data","Coins","Gems","TotalSnow","Blowers","BackPacks")
game.Players.PlayerAdded:Connect(function(player)
wait(1)
local UserId = player.UserId
local stats = player.leaderstats
local Coins = stats.Coins
local TotalSnow = stats.TotalSnow
local blowers = player.Items.Blowers:GetChildren()
local BackPacks = player.Items.BackPacks:GetChildren()
local Gems = player.leaderstats.Gems
-- load data
local TotalSnowdataStore = ds2("TotalSnow",player)
local CoinsDataStore = ds2("Coins",player)
local GemsDataStore = ds2("Gems",player)
local dataBlowersStore = ds2("Blowers",player)
local dataBackPacksStore = ds2("BackPacks",player)
TotalSnow.Value = TotalSnowdataStore:Get(0)
Coins.Value = CoinsDataStore:Get(0)
Gems.Value = GemsDataStore:Get(0)
for _, tbl in pairs(dataBlowersStore) do
local getfolder = blowers[tbl[3]]
if getfolder ~= nil then
getfolder.Equipt.Value, getfolder.Purchased.Value = tbl[1], tbl[2]
print(getfolder.Equipt.Value)
end
end
for _, tbl in pairs(dataBackPacksStore) do
local getfolder = BackPacks[tbl[3]]
if getfolder ~= nil then
getfolder.Equipt.Value, getfolder.Purchased.Value = tbl[1], tbl[2]
print(getfolder.Equipt.Value)
end
end
TotalSnowdataStore:OnUpdate(function(NewValue)
print("Value Updates",NewValue)
TotalSnow.Value = NewValue
end)
CoinsDataStore:OnUpdate(function(NewValue)
print("Value Updates",NewValue)
Coins.Value = NewValue
end)
GemsDataStore:OnUpdate(function(NewValue)
print("Value Updates",NewValue)
Gems.Value = NewValue
end)
dataBackPacksStore:OnUpdate(function(NewValue)
print("Value Updates",NewValue)
dataBlowersStore:OnUpdate(function(NewValue)
print("Value Updates",NewValue)
end)
end)
end)
while wait(5) do
for i,player in pairs(game.Players:GetChildren()) do
local BlowerStore = ds2("Blowers",player)
local BackPackStore = ds2("BackPacks",player)
local tableToStoreBlowers = {}
for _, blower in pairs(player.Items.Blowers:GetChildren()) do
table.insert(tableToStoreBlowers, {blower.Equipt.Value, blower.Purchased.Value, blower.Name})
end
local tableToStoreBackPacks = {}
for _, Backpack in pairs(player.Items.BackPacks:GetChildren()) do
table.insert(tableToStoreBackPacks, {Backpack.Equipt.Value, Backpack.Purchased.Value, Backpack.Name})
end
BlowerStore:Set(tableToStoreBlowers)
BackPackStore:Set(tableToStoreBackPacks)
end
end
It isn’t working, probably because of a stupid reason. Can someone help me out? Thanks.