Using require(ModuleID) and InsertService:LoadAsset() in pcall?

InsertService:LoadAsset() is a yielding function as stated in the wiki (probably the same applies to require(ModuleID)) and DataStore requests are also yielding functions. Is it a good practice to use these functions in a pcall? I’ve only seen such practice done using DataStores but not require() and :LoadAsset()

Edit:

An example of what I’m talking about

local Module

pcall(function()
    Module = require(ModuleID)
end)

local Asset

pcall(function()
    Asset = InsertService:LoadAsset(AsssetID)
end)
1 Like

i barly use loadasset. but for a yielding pcall in roblox i’d use a ypcall. as its stated to be the yielding version of pcall. require can be used by e.g. also datastores. your main datastore code goes in the module (as i use Object Orientated Programming. aka OOP for it) and you basically call all its functions of the module to your script.

edit
this is all the script does. everything important is done in the module script. even the (y)pcall for data
afbeelding

1 Like

Yeah, it’s a good practice. Those could fail due to connectivity or database errors that are beyond your control, and you’ll need to handle them if you want your code to be robust.

1 Like

Roblox’s version of pcall can yield. ypcall and pcall are basically the same.

https://devforum.roblox.com/t/pcall-vs-ypcall/24617/3?u=xaxa

(ypcall isn’t even documented in the wiki!)

2 Likes

i did not know that, i remember reading that ypcall is basically the yielding version of pcall. i guess ypcall is excessive to use since it is a thing which isn’t documented on the wiki for some reason. is there really any reason to not depricate ypcall?

Since it isn’t even documented in the wiki (anymore, at least), something tells me that it’s all but deprecated. It makes sense to still keep it around, though, since you might import libraries that aren’t written specifically for Roblox and those libraries might be using ypcall.

(Also I think it’s a bit weird to deprecate stuff that were in vanilla Lua. It would definitely be a first!)

EDIT: Okay on second thought this wouldn’t be a first. string.dump is useless in Roblox because it’s effectively been disabled to prevent exploits. The point still stands, though.

This is a bad way of doing it. Consider this method

local Success, Asset = pcall(InsertService.LoadAsset, InsertService, AssetID)

print(Success and 'Succesfully loaded asset' or Asset)
4 Likes