Hi, I'm trying to make a datastore that saves string instead of int as this is a weapon datastore. This worked perfectly fine but there are 2 problems that I wanted to fix. The first problem that I want to reduce the risk of losing data using my datastore and a way of doing this is by using UpdateAsync. I've tried using this from line 37- 36 but it keep returning a nil value so I'm asking you guys to help me put updateasync in line 35 and 53 section. The other problem with this is that I can't put too much data fast. I'm not sure how to explain this but when I try to add a boolvalue with the name of the weapons in my folder, I can only save it after 6 seconds or else I would receive this error "DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 185862361". Is there a way to shorten the time between data saving? Or else, I guess I would have to make the process of buying the weapons take about 7 sec.
local datastore = game:GetService("DataStoreService"):GetDataStore("WeaponStorage")
local rep = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(plr)
local chest = Instance.new("Folder")
chest.Parent = plr
chest.Name = "PlrWeapons"
local stat
local success , erro = pcall(function()
stat = datastore:GetAsync(plr.UserId)
end)
-- Create bool value for each of the string saved
if stat and success then
for i,v in pairs(stat) do
pcall(function()
if rep.Weapons:FindFirstChild(v)then
local tag = Instance.new("BoolValue")
tag.Parent = chest
tag.Name = v
end
end)
end
else
local tag = Instance.new("BoolValue")
local tag2 = Instance.new("BoolValue")
local tag3 = Instance.new("BoolValue")
tag.Name = "Wooden Sword"
tag2.Name = "Wooden Spear"
tag3.Name = "Wooden Bow"
tag.Parent = chest
tag2.Parent = chest
tag3.Parent = chest
end
-- Saving when something is added to the folder, I'm trying to make it similar to datastore2 so I don't have to save the data when the player leave which may cause some data lost
chest.ChildAdded:Connect(function(new)
if rep.Weapons:FindFirstChild(new.Name)then
local weapons = {} -- creating a table to put string values in
for i,v in pairs(plr.PlrWeapons:GetChildren())do
table.insert(weapons, v.Name) --Add all of the name of the boolvalue in the table
end
local success, err = pcall(function()
datastore:SetAsync(plr.UserId, weapons) --Tryin to change this to UpdateAsync
end)
if err then
warn(err)
end
else
new:Destroy()
end
end)
end)
-- Saving before the server closed
game:BindToClose(function()
wait(6) -- this is so that the error doesn't appear, Key = 185862361
for i, plr in pairs(game.Players:GetPlayers()) do
local weapons = {} -- creating a table to put string values in
for i,v in pairs(plr.PlrWeapons:GetChildren())do
table.insert(weapons, v.Name) --Add all of the name of the boolvalue in the table
end
local success, err = pcall(function()
datastore:SetAsync(plr.UserId, weapons) --Tryin to change this to UpdateAsync
end)
if err then
warn(err)
end
end
end)
Is there a way to save string values using datastore2? because as I know, the only way to change the value using datastore2 is :Increment() but I'm not sure if it's similar to table.insert() for me to save string value using datastore2.
Help please, Thank you!
