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

2 comments

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

0

I dont think saving any value based on Changed is a good idea. On leave and shutdown are the best bet.