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

Which loop method is it better to save a datastore by?

Asked by 5 years ago

One method I use is this also yuan is like a int value

local YuanDB = false -- true if a thread is in the process of saving
local YuanWaiting = false -- true if a thread is waiting for a chance to save
Yuan.Changed:Connect(function()
    if YuanWaiting then return end -- this function is being run and another thread is waiting to run
    YuanWaiting = true
    while YuanDB do wait(1) end
    YuanWaiting = false
    YuanDB = true
    local success = pcall(function()
        datast1:SetAsync(plr.UserId, Yuan.Value)
    end)
    if success then
        print('Data has been saved')
    else
        print('Data failed to save. Error message:", msg')
    end
    wait(60)  --How long it gonna take to save
    YuanDB = false
local YuanDB = false -- true if a thread is in the process of saving
local YuanWaiting = false -- true if a thread is waiting for a chance to save
Yuan.Changed:Connect(function()
    if YuanWaiting then return end -- this function is being run and another thread is waiting to run
    YuanWaiting = true
    while YuanDB do wait(1) end
    YuanWaiting = false
    YuanDB = true
    local success = pcall(function()
        datast1:SetAsync(plr.UserId, Yuan.Value)
    end)
    if success then
        print('Data has been saved')
    else
        print('Data failed to save. Error message:", msg')
    end
    wait(60)  --How long it gonna take to save
    YuanDB = false

or this simple method

while wait(60) do
Yuan:SetAsync
0
Honestly, I believe that Data is preferably Saved as the Player leaves the Game. I believe this reduces Exhaust risks, also causes a lot less lag Ziffixture 6913 — 5y
0
I dont think saving any value based on Changed is a good idea. On leave and shutdown are the best bet. DinozCreates 1070 — 5y

Answer this question