Hello! I have a problem with server overloading. It’s about some devproducts you can buy to kill people in different ways. When a button is pressed (to buy the selected devproduct) a remote is fired with the selected player and then a value called “Action” gets changed to it. My problem is that the server script for this task gets overloaded and has around 100-110 rate/s which sometimes breaks my products module which handles all the functions for the devproducts. Here is the script:
local mk = game:GetService("MarketplaceService")
local plrs = game:GetService("Players")
local module = require(game:GetService("ReplicatedStorage").Assets:WaitForChild("DevProducts"))
local event = game:GetService("ReplicatedStorage").Assets:WaitForChild("BuyProduct")
local ds = game:GetService("DataStoreService"):GetOrderedDataStore("RobuxSpent")
local addnotif = game:GetService("ReplicatedStorage").Assets:WaitForChild("AddNotif")
game.Players.PlayerAdded:Connect(function(plr)
local robuxspent = Instance.new("IntValue", plr)
robuxspent.Name = "RobuxSpent"
robuxspent.Value = 0
local action = Instance.new("StringValue", plr)
action.Name = "Action"
local datanotloaded = Instance.new("StringValue", plr) ; datanotloaded.Name = "DataNotLoaded"
local data
local sc, er = pcall(function()
data = ds:GetAsync(plr.UserId)
if data then
robuxspent.Value = data
end
end)
if not sc then warn(er) end
datanotloaded:Destroy()
end)
event.OnServerEvent:Connect(function(plrthatbought, plrtoaction)
if plrtoaction and plrtoaction[1] then
plrthatbought.Action.Value = plrtoaction[1]
end
task.wait()
end)
function processreceipt(info)
local plr = plrs:GetPlayerByUserId(info.PlayerId)
if not plr then return Enum.ProductPurchaseDecision.NotProcessedYet end
if plr then
local id = info.ProductId
local price
for i,v in pairs(module.Products) do
if module.Products[i].ProductId == id then
local tb = {}
print(plr.Name.." has purchased".." "..i.." targeting ".. plr.Action.Value.."!")
table.insert(tb, plr.Action.Value)
price = module.Products[i].Price
local delaytime = 2.5
wait(delaytime)
print(tb, plr.Name)
module.Products[i].Function(tb, plr)
addnotif:FireAllClients(plr.Name, plr.Action.Value, i)
end
end
if price and price > 1 then
plr:FindFirstChild("RobuxSpent").Value += price
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
mk.ProcessReceipt = processreceipt
game.Players.PlayerRemoving:Connect(function(plr)
if plr:FindFirstChild("DataNotLoaded") then return end
local sc, er = pcall(function()
ds:SetAsync(plr, plr:FindFirstChild("RobuxSpent").Value)
end)
if not sc then warn(er) end
end)
I can’t seem to find the part which overloads the server.
This sky should get deleted but it doesn’t, although in server which aren’t as overloaded as this one, it does get.
Are maybe the amount of datastore requests the problem?
Thanks!