I was wondering what the best way to store a lot of data would be, im using a table currently but it will get very long.
local dataStoreService = game:GetService("DataStoreService")
local invstore = dataStoreService:GetDataStore("invstore")
local players = game:GetService("Players")
local function save(player)
local ok, exception_data = pcall(
invstore.SetAsync,
invstore,
player.UserId,
{
Koala = player.DataValues.KoalaCounter.Value,
countstat = player.DataValues.Count.Value,
walk20 = player.WalkspeedShop.W20.Value,
walk23 = player.WalkspeedShop.W23.Value
}
)
if ok then
print("Data successfully saved")
else
-- Implement retrying logic or sum
warn(exception_data)
end
return ok, exception_data
end
game.Players.PlayerAdded:Connect(function(player)
local DataValues = Instance.new("Folder")
DataValues.Name = "DataValues"
DataValues.Parent = player
local WalkspeedShop = Instance.new("Folder")
WalkspeedShop.Name = "WalkspeedShop"
WalkspeedShop.Parent = player
local W20 = Instance.new("BoolValue")
W20.Name = "W20"
W20.Parent = WalkspeedShop
local W23 = Instance.new("BoolValue")
W23.Name = "W23"
W23.Parent = WalkspeedShop
local KoalaCounter = Instance.new("IntValue")
KoalaCounter.Name = "KoalaCounter"
KoalaCounter.Parent = DataValues
local count = Instance.new("IntValue")
count.Name = "Count"
count.Parent = DataValues
local ok, data = pcall(invstore.GetAsync, invstore, player.UserId)
if ok then
if data then
KoalaCounter.Value = data.Koala
count.Value = data.countstat
W20.Value = data.walk20
W23.Value = data.walk23
else
-- Give some default data i guess?
end
print("yes, data successfully loaded")
else
-- implement some retrying logic or sum
warn("Nope,", data)
end
end)
players.PlayerRemoving:Connect(function(player)
local ok, exception_data = save(player)
if not ok then
-- retry
end
end)
game:BindToClose(function()
for _, player in ipairs(players:GetPlayers()) do
coroutine.wrap(save)(player)
end
end)

1 comment
Stop reposting the same question it has been answered more than 5 times.