Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to prevent datastore from throttling?

Asked by
B_rnz 171
5 years ago
Edited 5 years ago

I heard that it takes a wait time of 6 seconds to SetAsync a players data. But I am trying to set ALL of the player's data before as the player is removed. But I am stuck on what to do here..

Module script:

return {
    PlayerData = { Coins = 0, Diamonds = 0, Experience = 0, Kills = 0, Level = 0, EXPneeded = 0, }
}

script:

local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("PlayerDataV1");
local DataModule = require(game.ReplicatedStorage.PlayerData)


game.Players.PlayerAdded:Connect(function(plr)
    for i, v in pairs(DataModule.PlayerData) do
        DataModule.PlayerData[i] = DataStore:GetAsync(plr.UserId, i)  -- this is good.
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    for i, v in pairs(DataModule.PlayerData) do
        DataModule.PlayerData['Coins'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['Coins']) --[[
        DataModule.PlayerData['Diamonds'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['Diamonds'])
        DataModule.PlayerData['Experience'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['Experience'])
        DataModule.PlayerData['Kills'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['Kills'])
        DataModule.PlayerData['Level'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['Level'])
        DataModule.PlayerData['EXPneeded'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['EXPneeded'])
        ]]--  I want to add the rest of these without throttle.
    end
end)

1 answer

Log in to vote
1
Answered by 5 years ago

Try storing all of your player data in one dictionary that can be posted to SetAsync in one call.

From looking at your system, that may require a rewrite.

You don't want to store everything within individual tables, across players, but instead have each player have one table that has tables inside of it with the appropriate values in place.

Structured like so:

Player.Name
    Coins
        1400
    Diamonds
        2000
    Experience
        67920
0
It is, my module script have playerdata = {info is in here.} I should post the Module script too. B_rnz 171 — 5y
0
Oh. Then why aren't you calling it like that? If you're making calls to tables the other way around then it doesn't seem like you're doing it that way. Can you post the ModuleScript? Parkatr0n 20 — 5y
0
Yes, I posted it. B_rnz 171 — 5y
0
Yeah, just set the entire thing as the current PlayerData and then get each value out of the table. You don't have to post one singular number to SetAsync, you can post an entire table if you need to. Parkatr0n 20 — 5y
View all comments (3 more)
0
I want to save not one instance, but all, at the same time, I want to prevent it from throttling as the player leaves the game. B_rnz 171 — 5y
0
Right. Currently you're unpacking each individual value and pushing them individually, and what you might want to do is instead push the entire PlayerData table. There won't be any throttling if a bunch of players leave at once, either. Parkatr0n 20 — 5y
0
It works, but my studio still crashes everytime I leave it. B_rnz 171 — 5y
Ad

Answer this question