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

DataStore - Try sending fewer requests?

Asked by
TriteA1 30
4 years ago

Yo, so I've made a bool value inside leaderstats script that I copied from a tutorial. The Bool Value says whether or not a player owns a vehicle. I have two values, Money and the Vehicle. The vehicle saves, however the money does not. Any help is appreciated.

Error: DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = Money-226030996

local currencyName = "Money"
local Car1Owned = "Car1Owned"
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")

game.Players.PlayerAdded:Connect(function(player)

    local folder = Instance.new("Folder")
    folder.Name = "leaderstats" 
    folder.Parent = player

    local currency = Instance.new("IntValue")
    currency.Name = currencyName
    currency.Parent = folder

    local Owned = Instance.new("BoolValue")
    Owned.Name = Car1Owned
    Owned.Parent = folder

    local ID = currencyName.."-"..player.UserId


    local savedData = nil

    pcall(function()
        savedData = DataStore:GetAsync(ID)
    end)

    if savedData ~= nil then
        Owned.Value = savedData
        currency.Value = savedData
        print("Data loaded")
    else
        -- new player
        currency.Value = 1000
        print("New player to the game")
    end

end)

game.Players.PlayerRemoving:Connect(function(player)
    local ID = currencyName.."-"..player.UserId
    DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
    DataStore:SetAsync(ID,player.leaderstats[Car1Owned].Value)
end)

1
You’re overwriting it ankurbohra 681 — 4y

1 answer

Log in to vote
0
Answered by
Filipalla 504 Moderation Voter
4 years ago
Edited 4 years ago

You are saving Currency and Owned on the same key overwriting whichever saves first(in this case currency gets overwritten), you are gonna need to have two different ID's(keys) to save them on, i.e

Note: You are gonna have to change the GetAsync part to use two different ID's too

local CurrencyID = currencyName.."-"..player.UserId
local Car1OwnedID = Car1Owned.."-"..player.UserId
DataStore:SetAsync(CurrencyID,player.leaderstats[currencyName].Value)
DataStore:SetAsync(Car1OwnedID,player.leaderstats[Car1Owned].Value)

see Datastore

Don't forget to mark my answer as the solution and upvote it if it solved your problem :)

If you need more help please post a comment

0
Thanks mate! Appreciate the help. TriteA1 30 — 4y
0
np Filipalla 504 — 4y
Ad

Answer this question