Script Wait in C# Crashing

var model = new CitizenFX.Core.Model(PedHash.Cop01SFY);

model.Request();

while (!model.IsLoaded)
    Function.Call(Hash.WAIT, 0); // this is what's crashing it

Function.Call(Hash.SET_PLAYER_MODEL, model.Hash);
Function.Call(Hash.SET_PED_DEFAULT_COMPONENT_VARIATION, LocalPlayer);

model.MarkAsNoLongerNeeded();

How can I call WAIT while waiting for the model to load without crashing the game?

await BaseScript.Delay(0);

and making your entire call chain of async Task (and await-ing) rather than just calling directly.

2 Likes