Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Callback doesn't yield in this save function?

Hi! I've been receiving this error when trying to save a players wins, the error I got was Callbacks cannot yield, I was wondering what part of the code caused it and why? Any help is appreciated :D

		local Success = false 
		local PlayerId = ("PlayerID_"..Player.UserId)
		local WinVal = Player.leaderstats.Wins.Value
		
		
		local successfulSave,ErrorMessage = pcall(function()
			
			GameDataStore:UpdateAsync(PlayerId,function(OldValue)

				if WinVal >= OldValue then
					GameDataStore:SetAsync(PlayerId,WinVal) 
				else
					GameDataStore:SetAsync(PlayerId,OldValue) 
				end
			end)

2 answers

✓ Accepted answer

:UpdateAsync doesnt need to use SetAsync to update the data, it just needs to return the data. Here's a example!

local Success = false 
local PlayerId = ("PlayerID_"..Player.UserId)
local WinVal = Player.leaderstats.Wins.Value


local successfulSave,ErrorMessage = pcall(function()

    GameDataStore:UpdateAsync(PlayerId,function(OldValue)

        if WinVal >= OldValue then
            GameDataStore:SetAsync(PlayerId,WinVal) -- return the data rather than using :SetAsync
        else
           return OldValue -- return the data,  will definately save
    end)
end)

Please mark this as a solution if this helps you!

1 comment

0

didn't know about the return OldValue - learnt something new, cheers :D

This discussion is preserved as it was. New answers, comments, and votes are closed.