Since DataStore OnUpdate is broken I have to come up with another way to check for a New Place Version with Datastore so I did, but the problem is that I keep getting this error cannot resume non-suspended coroutine
I’m not sure why but I think it’s because of the xpcall() see code below
Code
-- PlaceVersion DataStore --
if not RunS:IsStudio() then
local GameDataStore = DataStoreService:GetDataStore('Name','Scope')
local Saved_PlaceVersion,Result
local Default_WaitTime = 60
local Extra_WaitTime = 0
local function GetANDCompare_PlaceVersions_Func()
local Success = pcall(function() Saved_PlaceVersion = GameDataStore:GetAsync("PlaceVersion") end)
if Success and Saved_PlaceVersion then
Result = Current_PlaceVersion == Saved_PlaceVersion and 'Lastest_Version' or Current_PlaceVersion < Saved_PlaceVersion and 'Outdated_Version' or Current_PlaceVersion > Saved_PlaceVersion and 'New_Version'
print('Time',tick())
return
end
wait(Default_WaitTime)
end
local function CheckForPlaceVersionUpdate_Func()
while wait(5) do
if DataStoreService:GetRequestBudgetForRequestType(1) >= 5 and xpcall(GetANDCompare_PlaceVersions_Func,GetANDCompare_PlaceVersions_Func) then
if Result == 'Outdated_Version' then
break
elseif Result == 'New_Version' then
GameDataStore:SetAsync("PlaceVersion",Current_PlaceVersion)
Extra_WaitTime = 600
elseif Result == 'Lastest_Version' then
Extra_WaitTime = 300
end
end
print(Result)
Result = nil
wait(Default_WaitTime+Extra_WaitTime)
end
end
spawn(CheckForPlaceVersionUpdate_Func)
end
You cannot yield in xpcall. Re-implement xpcall as the following:
local function xypcall(successProc, failureProc, ...)
-- Store it in a table to get all return values
local call = {ypcall(successProc, ...)}
-- Check if the pcall failed to call the failure proc
if not call[1] then
call = {ypcall(failureProc, select(2, unpack(call)))}
-- If the proc to call when failing errored, return "error in error handling"
if not call[1] then
return false, "error in error handling"
end
return false, select(2, unpack(call))
end
return true, select(2, unpack(call))
end
…or if you want to be less verbose than I am, just use ypcall and check if the success return is true or not.
This is not a correct alternative. The main point of xpcall is that the error handler is called just after the error, allowing the handler to retrieve a stack trace via debug.traceback. This is otherwise impossible without using a custom error function to intercept the error beforehand.
Hmm is that a bug? I know for sure pcall can yield. ypcall was added before that was the case, and then they changed pcall. I see no reason why xpcalls behavior shouldn’t be changed too.