Roblox Studio-DataStore request was added to queue - roblox

I am making Race clicker game
And this is my script of my code
and I am keep getting the error, "DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 2222391052"
And the leaderstats are not updating.
local dataStoreService = game:GetService("DataStoreService")
local leaderstatsDataStore = dataStoreService:GetDataStore("data")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local passions = Instance.new("IntValue", leaderstats)
passions.Name = "Passion"
local upgrades = Instance.new("IntValue", leaderstats)
upgrades.Name = "Hero Upgrade"
local MaxSpeed = Instance.new("IntValue",leaderstats)
MaxSpeed.Name = "Max Speed"
local leaderstatsData = leaderstatsDataStore:GetAsync(player.UserId)
if leaderstatsDataStore ~= nil then
passions.Value = leaderstatsData[1]
upgrades.Value = leaderstatsData[2]
MaxSpeed.Value = leaderstatsData[3]
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local values = {}
for _, child in pairs(player.leaderstats:GetChildren()) do
table.insert(values,child.Value)
end
pcall(function()
leaderstatsDataStore:SetAsync(player.UserId, values)
end)
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
local values = {}
for _, child in pairs(player.leaderstats:GetChildren()) do
table.insert(values,child.Value)
end
pcall(function()
leaderstatsDataStore:SetAsync(player.UserId, values)
end)
end
end)
Someone said that this is an error that happens if I send request more than 60 times a second.
But I can't really get what is sending so much requests.
So can anyone tell the changed code to me

That's not an error, that's a warning. (Errors are red, warnings are yellow.)
You are getting the warning because the server can't do multiple data store operations at once. Instead, it queues the operations and does them one by one. However, if the queue becomes too long, some requests get dropped. That's not happening in your case, so you don't have to care about it.

Related

I can't get my Data Store V2 to work, It always returns nil

I read the Data Store V2 documentation on the Dev Hub and tried to make a similar code, but I can't get it to work. It doesn't have any errors other than Attempt to index nil with Version because it can't get the Data. It returns Succes = true, and CurrentNumber, KeyInfo = nil. There are no errors when saving the data and the Succes variable is always returned true. I enabled the security configuration to allow data stores, the game is public and I tested it both on studio and the actual game(on Roblox). The code is in a script in the Server Script Service Here's the code:
local DataStoreService = game:GetService('DataStoreService')
local Players = game:GetService('Players')
-- Data Stores:
-- Enables Data Stores V2
local Options = Instance.new('DataStoreOptions')
Options:SetExperimentalFeatures({["v2"] = true})
local NumberStore:DataStore = DataStoreService:GetDataStore("PlayerNumber", "global", Options)
local SetOptions = Instance.new('DataStoreSetOptions')
SetOptions:SetMetadata({['PlayerNumberType'] = 'Int'})
local function SaveNumberData(Player:Player)
local Number = 1
local PlayerKey = 'Player_1234'
local Sucess, Errormessage = pcall(function()
NumberStore:SetAsync(PlayerKey, Number, {Player.UserId}, SetOptions)
end)
if not Sucess then
print(Errormessage)
else
print('Data Saved')
end
end
local function LoadPlayerData(Player:Player)
local PlayerKey = 'Player_1234'
local Sucess, CurrentNumber, KeyInfo:DataStoreKeyInfo = pcall(function()
NumberStore:GetAsync(PlayerKey)
end)
if Sucess then
print(CurrentNumber)
print(KeyInfo.Version)
print(KeyInfo.CreatedTime)
print(KeyInfo.UpdatedTime)
print(KeyInfo:GetUserIds())
print(KeyInfo:GetMetadata())
else
print(CurrentNumber)
end
end
Players.PlayerRemoving:Connect(SaveNumberData)
Players.PlayerAdded:Connect(LoadPlayerData)
I found the answer, I forgot to put return before NumberStore:GetAsync(PlayerKey)

How to send errors from Neovim LSP to ALE

ALE has an API for sending errors to it from other sources. I'm using this like shown below and it works for the first error. More specifically, if I make one edit that results in an LSP error, the error will be displayed by ALE in the location list. If I make any further keystrokes, the location list is emptied again.
I can also trigger this behavior if I disable LSP, load ALE, manually call ShowResults and then press any other key in insert mode.
My hypothesis is that ALEs linting in insert mode (per default) kicks in. If LSP is disabled and there are no linters registered for the current file type, it doesn't find any errors (obviously, there's nothing that could report any) and so it empties my location list again. So the steps are: open buffer without LSP, call ShowResults, location list opens, press i, press any key, location list is empty
Now I thought that it was because I wasn't implementing the full ALE API. So I added a hook (2nd snippet). I can verify that this hook is called and that it generates valid messages. If I keep the location list open I can even see all the expected errors flickering across the loclist. I can navigate to those errors with :lolder, but I don't know why ALE always adds another, empty location list, after the LSP is done doing its job.
Or maybe I'm doing something wrong here.
vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, _, params, client_id, _, config)
local uri = params.uri
local bufnr = vim.uri_to_bufnr(uri)
if not bufnr then
return
end
local diagnostics = params.diagnostics
if not diagnostics or vim.tbl_isempty(diagnostics) then
vim.fn['ale#other_source#ShowResults'](bufnr, "nvim-lsp", {})
return
end
-- Important so we can pull diagnostics from this table when ALE asks for
-- them
vim.lsp.diagnostic.save(diagnostics, bufnr, client_id)
local messages = {}
for _, event in ipairs(diagnostics) do
-- :h ale-localist-format
local msg = {}
msg.text = event.message
msg.lnum = event.range.start.line
msg.end_lnum = event.range["end"].line
msg.col = event.range.start.character
msg.end_col = event.range["end"].character
msg.bufnr = bufnr
msg.nr = event.severity
table.insert(messages, msg)
end
vim.fn['ale#other_source#ShowResults'](bufnr, "nvim-lsp", messages)
end
Second snippet which is called from the 'on_attach' function of the Neovim LSP
function ALEHook(bufnr)
vim.fn['ale#other_source#StartChecking'](bufnr, "nvim-lsp")
local diagnostics = vim.lsp.diagnostic.get(bufnr, client.id)
if not diagnostics or vim.tbl_isempty(diagnostics) then
vim.fn['ale#other_source#ShowResults'](bufnr, "nvim-lsp", {})
return
end
local messages = {}
for _, event in ipairs(diagnostics) do
local msg = {}
msg.text = event.message
msg.lnum = event.range.start.line
msg.end_lnum = event.range["end"].line
msg.col = event.range.start.character
msg.end_col = event.range["end"].character
msg.bufnr = bufnr
msg.nr = event.severity
table.insert(messages, msg)
end
vim.fn['ale#other_source#ShowResults'](bufnr, "nvim-lsp", messages)
end
api.nvim_command('augroup ALEHookLSP')
api.nvim_command('autocmd!')
api.nvim_command('autocmd User ALEWantResults call v:lua.ALEHook(g:ale_want_results_buffer)')
api.nvim_command('augroup END')

Roblox: BindToClose works, PlayerRemoving does not

I am trying to store CFrame X, Y, and Z data into DataStore so that the player can start off where they left off. I am testing by trying to save hardcoded values.
The loading of data using PlayerAdded works fine.
For some reason, the SetAsync() in PlayerRemoving wasn't completing when the player leaves in game or in studio. The weird thing is that when I added BindToClose, the save function runs correctly when in Studio but not in game.
If anyone can tell me why, I'd be very grateful.
local function save(plr)
local data = {
CFrameX = -1232;
CFrameY = 1232;
CFrameZ = -1235;
}
local success, errormessage = pcall(function()
MandoSimStore:SetAsync(plr.UserId.."-Location_StorageData", data)
end)
if success then
print("Successfully saved data!")
else
warn("ERROR: "..errormessage)
end
end
local gameShutDown = false
game.Players.PlayerRemoving:Connect(function(plr)
wait(0.1)
if not gameShutDown then
save(plr)
end
end)
game:BindToClose(function()
gameShutDown = true
for _, plr in ipairs(game.Players:GetPlayers()) do
save(plr)
end
end)
Maybe try
wait(1)
It worked for me

BodyPosition not changing?

I've been sitting at my laptop for about an hour trying to figure out what's going on. I did this exact same thing yesterday and it worked. Please help.
Explaining the program:
The program takes the object that the mouse is pointing at, if you click the object gravitates toward the mouse.
local player = game.Players.LocalPlayer
local runservice = game:GetService("RunService")
local character = player.Character
local humanoid = character.Humanoid
local camera = workspace.Camera
local mouse = player:GetMouse()
local mousepos = mouse.hit.p
local grabbed = false
local function grabbedobj(obj) --this is the thing i need help on
local bodypos = obj.BodyPosition.Position
local pos = obj.Position
obj.Anchored = false
mouse.Button1Down:Connect(function()
grabbed = true
end)
mouse.Button1Up:Connect(function()
grabbed = false
end)
if grabbed == true then
print(obj.BodyPosition.Position)
bodypos = Vector3.new(mousepos.X, mousepos.Y, mousepos.Z) --really important
end
if grabbed == false then
bodypos = Vector3.new(pos.X, -25, pos.Z)
pos = Vector3.new(bodypos.X, pos.Y, bodypos.Z)
end
end
local function setup()
mousepos = mouse.hit.p
if mouse.Target ~= nil and mouse.Target.Parent == game.Workspace.IntObj then
grabbedobj(mouse.Target) --takes object that the mouse is pointing at
end
end
while wait(.1) do
setup()
end
Lets shuffle the code a little bit so it does what I think you want to do. You might have mixed up some things while trying to debug this. So here:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local grabbed = false
local obj
mouse.Button1Down:Connect(function()
if mouse.Target ~= nil and mouse.Target.Parent == game.Workspace.IntObj then
obj = mouse.Target
obj.Anchored = false
grabbed = true
end
end)
mouse.Button1Up:Connect(function()
if (grabbed) then
grabbed = false--BodyPosition
obj.BodyPosition.Position = Vector3.new(obj.Position.X, 0.1, obj.Position.Z)
obj.Anchored = true
end
end)
local function move()
if (grabbed) then
local mousepos = mouse.hit.p
obj.BodyPosition.Position = Vector3.new(mousepos.X, mousepos.Y, mousepos.Z)
print(obj.BodyPosition.Position)
end
end
while wait(.1) do
move()
end
When you click the mouse it checks if you click your part that is in IntObj. It will retain a reference to that part and then moves it with the mouse. When you release the button it will drop it at its location.
So this LocalScript should work but it has an issue updating the BodyPosition as you said in the title. The reason for that is that you can only update server parts from your client if you give the client permission from the server for it. You could write a remote function on the server and say:
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(plr)
Workspace.IntObj.Part:SetNetworkOwner(plr)
end
If you call this from your local script's initialization, it will work. Note, that your part cannot be anchored for that.
Another way would be to just let the server do the updating. So instead of setting the
obj.BodyPosition.Position on the client you would call the remote function like this:
game.ReplicatedStorage.RemoteFunction:InvokeServer(Vector3.new(mousepos.X, mousepos.Y, mousepos.Z))
and then on the server you set the position:
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(plr, bodyPos)
script.Parent.BodyPosition.Position = bodyPos
end
In that case, if you anchor/unanchor the part, do that on the server as well. Otherwise you'll get weird results.

Simplest way to process a list of items in a multi-threaded manner

I've got a piece of code that opens a data reader and for each record (which contains a url) downloads & processes that page.
What's the simplest way to make it multi-threaded so that, let's say, there are 10 slots which can be used to download and process pages in simultaneousy, and as slots become available next rows are being read etc.
I can't use WebClient.DownloadDataAsync
Here's what i have tried to do, but it hasn't worked (i.e. the "worker" is never ran):
using (IDataReader dr = q.ExecuteReader())
{
ThreadPool.SetMaxThreads(10, 10);
int workerThreads = 0;
int completionPortThreads = 0;
while (dr.Read())
{
do
{
ThreadPool.GetAvailableThreads(out workerThreads, out completionPortThreads);
if (workerThreads == 0)
{
Thread.Sleep(100);
}
} while (workerThreads == 0);
Database.Log l = new Database.Log();
l.Load(dr);
ThreadPool.QueueUserWorkItem(delegate(object threadContext)
{
Database.Log log = threadContext as Database.Log;
Scraper scraper = new Scraper();
dc.Product p = scraper.GetProduct(log, log.Url, true);
ManualResetEvent done = new ManualResetEvent(false);
done.Set();
}, l);
}
}
You do not normally need to play with the Max threads (I believe it defaults to something like 25 per proc for worker, 1000 for IO). You might consider setting the Min threads to ensure you have a nice number always available.
You don't need to call GetAvailableThreads either. You can just start calling QueueUserWorkItem and let it do all the work. Can you repro your problem by simply calling QueueUserWorkItem?
You could also look into the Parallel Task Library, which has helper methods to make this kind of stuff more manageable and easier.