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

Datastore problem not saving after 30 times changes?

Asked by 4 years ago
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CoinsSaveSystem")

game.Players.PlayerAdded:connect(function(plr)
    local ls = Instance.new("Folder", plr)
    ls.Name = "leaderstats"
    local st = Instance.new("StringValue")
    st.Name = "Coins"
    st.Parent = ls
    st.Value = 0

 st.Value = ds1:GetAsync(plr.UserId) or 0
 ds1:SetAsync(plr.UserId, st.Value)


 st.Changed:connect(function()
 ds1:SetAsync(plr.UserId, st.Value)

end)
end)

11:52:19.993 - DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 38381653 (x21)

after x30 requests are sent this just drops the saves, how do i make this infinite? if its even possible.

0
Roblox limits how many request Datastore can take, maybe make it just save when the player leaves? Akkoza 0 — 4y
0
Too much request make Datastore drop. You can save when player leave and server close. or use DataStore2 DurVooDoo 30 — 4y
0
I don`t know if this is the best way, but I usually have a different table in module script that saves the value and player who requested, and will save the player`s data no matter if player is in the game or not. However, use still should save data when player leaves as this might drop if actual server closes due to crashes or when you are the last player to leave. Yuuwa0519 197 — 4y
0
Perhaps you could update it everytime the player collects a certain amount. Then any others which aren't saved, can be saved as player leaves. That way you don't have constant requests to save. xXTouchOfFrostXx 125 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

How do i save when a player leaves?

local DataStoreService = game:GetService("DataStoreService")
local saveDataStore = DataStoreService:GetDataStore("ChangeThis")

-- When the player join load the saved stats
game.Players.PlayerAdded:connect(function(plr)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = plr

    -- example with 2 data (cash & kill) you can add more if you want
    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Value = 10
    cash.Parent = leaderstats

    local kill = Instance.new("IntValue")
    kill.Name = "Kill"
    kill.Value = 0
    kill.Parent = leaderstats

    -- Get the saved data
    local data = saveDataStore:GetAsync(plr.UserId)
    if data then
        for i, v in pairs(leaderstats:GetChildren()) do
            v.Value = data[v.Name]
        end
    end
end)

-- When the player leave save the data
game.Players.PlayerRemoving:connect(function(plr)
    local leaderstats = plr:FindFirstChild("leaderstats")
    if leaderstats then
        local saveData = {}
        for i, v in pairs(leaderstats:GetChildren()) do
            saveData[v.Name] = v.Value
        end
        saveDataStore:SetAsync(plr.UserId, saveData)
    end
end)
0
Tysm! popu2004 42 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

There's too many requests, you can save data in intervals of 5-10mins and when the player leaves.

0
How do i save when a player leaves? popu2004 42 — 4y

Answer this question