Playfab Cloud Script Revisions (Legacy)

Hello!

I’m making my first multiplayer game with Photon and Playfab.

Everything is fine but I need something that playfab doesn’t support out of the box.

The game has a Playfab leaderboard and I need when the logged in player (Player A with ID 657654765) gets some points, another player (Player B with ID 989876546) gets some points too although he didn’t participate on any match.

Playfab script

handlers.updateLeaderboard = function (args, context) {
    var winnerId = args.winnerId;
    var specificPlayerId = args.specificPlayerId;
    var points = args.points || 45; // Default to 45 points if not specified

    // Function to update player statistics
    var updateStats = function (playerId) {
        var updateRequest = {
            PlayFabId: playerId,
            Statistics: [
                {
                    StatisticName: "Score",
                    Value: points
                }
            ]
        };

        return new Promise((resolve, reject) => {
            server.UpdatePlayerStatistics(updateRequest, function (result, error) {
                if (error) {
                    log.error("Error updating stats for player " + playerId + ": " + JSON.stringify(error));
                    reject(error);
                } else {
                    log.info("Successfully updated stats for player " + playerId + ": " + JSON.stringify(result));
                    resolve(result);
                }
            });
        });
    };

    // Update both players' statistics and return the results when both are done
    return Promise.all([
        updateStats(winnerId),
        updateStats(specificPlayerId)
    ]).then(results => {
        log.info("Both players' stats updated successfully.");
        return {
            winnerUpdate: results[0],
            specificPlayerUpdate: results[1]
        };
    }).catch(error => {
        log.error("Error in updating player statistics:", JSON.stringify(error));
        throw new Error(error.message);
    });
};

Solar2d Code

function playfab.updateLeaderboardWithCloudScript(winnerId, specificPlayerId, points)
    		local request = {
        		FunctionName = "updateLeaderboard",
        		FunctionParameter = {
            		winnerId = winnerId,
            		specificPlayerId = specificPlayerId,
           		 	points = points
       			},
        		GeneratePlayStreamEvent = true
    		}

    		PlayFabClientApi.ExecuteCloudScript(
        		request,
        		function(result)
            		print("Cloud Script executed successfully.")
            		print("Full result: " .. json.encode(result))
            		if result.FunctionResult then
                		print("Winner update result: " .. json.encode(result.FunctionResult.winnerUpdate))
                		print("Specific player update result: " .. json.encode(result.FunctionResult.specificPlayerUpdate))
            		end
        		end,
        		function(error)
            		print("Error executing Cloud Script: " .. error.errorMessage)
        		end
    		)
		end
		local winnerId = playfab.playerId -- actual logged in player
		local specificPlayerId = "948708848AE21BD" -- player b
		local points = 45  -- Points to be awarded
		-- Call the Cloud Script to update the leaderboard
		playfab.updateLeaderboardWithCloudScript(winnerId, specificPlayerId, points)

Solar2D accesses js function just fine but there is no score / points update for player b.

I’m pretty sure that the issue is in js code and I’m a complete noob on js.

Also here is Solar2d Console info that shows that at least the script gets executed.

Cloud Script executed successfully.
Full result: {"Revision":8,"FunctionName":"updateLeaderboard","FunctionResult":[],"ExecutionTimeSeconds":0.1564465,"ProcessorTimeSeconds":0.001904,"Logs":[],"APIRequestsIssued":2,"HttpRequestsIssued":0,"MemoryConsumedBytes":7384}
                    Winner update result: null
                    Specific player update result: null

Any help is much appreciated because I do not know what else to try!