I am trying to run a test script on all my players to give them a random stat for testing leaderboards.
I created a cloud script and attempt to use the conext.playerProfile to get the PlayerID but I get the following error when I run the task on the 'All Players' segment:
{ "TaskInstanceId": "DC9E527E00184FF8-4", "TaskIdentifier": { "Name": "Add Random Stat", "Id": "DC9E527E00184FF8" }, "StartedAt": "2019-02-20T13:54:14.8847531", "CompletedAt": "2019-02-20T13:54:15.0097562", "Status": "Failed", "PercentComplete": null, "EstimatedSecondsRemaining": null, "ScheduledByUserId": "B5F874538A90EC25", "Result": { "FunctionName": "randomXPStat", "Revision": 49, "FunctionResult": null, "FunctionResultTooLarge": null, "Logs": [], "LogsTooLarge": null, "ExecutionTimeSeconds": 0.00041569999999999997, "ProcessorTimeSeconds": 0, "MemoryConsumedBytes": 29792, "APIRequestsIssued": 0, "HttpRequestsIssued": 0, "Error": { "Error": "JavascriptException", "Message": "JavascriptException", "StackTrace": "TypeError: Cannot read property 'PlayerId' of null\n at handlers.randomXPStat (BA50-main.js:134:20)" } } } The message suggests that 'profile' in my script is null, here is my script (line 134 is var id = profile.PlayerId;): handlers.randomXPStat = function (args, context){ var response; var profile = context.playerProfile; var v = Math.floor((Math.random() * 500) + 50); var id = profile.PlayerId; try{ server.UpdatePlayerStatistics({ "PlayFabId" : id, "Statistics" : [{ "StatisticName" : "xp", "Value" : v }] }); response = {error:false, errorCode:0, message:"Successfully updated"}; }catch (ex){ let error = ex.apiErrorInfo.apiError.error; let errorCode = ex.apiErrorInfo.apiError.errorCode; log.error(ex); response = {error:true, errorCode:errorCode, message:error}; } return {response: response} }; I ran the randomXPStat on a single Player, using current: currentPlayerId and that updated fine, I then tried it for All Players and failed, indicating that I needed to use the context