I want to add value (CurrentGameMoney) to a player statistics when I want to challenge, my code is working well good but not add a value to statistics when create room
Cloud Script
function getGameMoney (roomCategory) { switch (roomCategory) { case "1": return 100; break; case "2": return 500; break; case "3": return 2000; break; case "4": return 10000; break; case "5": return 20000; break; case "6": return 50000; break; case "7": return 100000; break; case "8": return 500000; break; case "9": return 1000000; break; default: return 0; break; } return 0; } function getGameCategory (roomMoney) { switch (roomMoney) { case 100: return 1; break; case 500: return 2; break; case 2000: return 3; break; case 10000: return 4; break; case 20000: return 5; break; case 50000: return 6; break; case 100000: return 7; break; case 500000: return 8; break; case 1000000: return 9; break; default: return 0; break; } return 0; } // Photon Webhooks Integration // // The following functions are examples of Photon Cloud Webhook handlers. // When you enable Photon integration in the Game Manager, your Photon applications // are automatically configured to authenticate players using their PlayFab accounts // and to fire events that trigger your CloudScript Webhook handlers, if defined. // This makes it easier than ever to incorporate server logic into your game. // // For more information, see https://playfab.com/using-photon-playfab // Triggered automatically when a Photon room is first created handlers.RoomCreated = function (args) { //log.debug("Room Created - Game: " + args.GameId + " MaxPlayers: " + args.CreateOptions.MaxPlayers); var userStatsResult = server.GetUserStatistics ({ PlayFabId: currentPlayerId }); var roomCategory = args.GameId.split(":")[1]; var money = getGameMoney (roomCategory); server.UpdateUserStatistics ({ PlayFabId: currentPlayerId, UserStatistics: { "CurrentGameMoney" : money }}); } // Triggered automatically when a player joins a Photon room handlers.RoomJoined = function (args) { //log.debug("Room Joined - Game: " + args.GameId + " PlayFabId: " + args.UserId); var userStatsResult = server.GetUserStatistics ({ PlayFabId: args.UserId }); var roomCategory = args.GameId.split(":")[1]; var money = getGameMoney (roomCategory); server.UpdateUserStatistics ({ PlayFabId: args.UserId, UserStatistics: { "CurrentGameMoney" : money }}); } // Triggered automatically when a player leaves a Photon room handlers.RoomLeft = function (args) { log.debug("Room Left - Game: " + args.GameId + " PlayFabId: " + args.UserId); var userStatsResult = server.GetUserStatistics ({ PlayFabId: currentPlayerId }); if (parseInt(userStatsResult.UserStatistics.GameStarted !== undefined ? userStatsResult.UserStatistics.GameStarted : 0) == 1 && parseInt(userStatsResult.UserStatistics.InGame !== undefined ? userStatsResult.UserStatistics.InGame : 0) == 1) { server.SubtractUserVirtualCurrency ({ PlayFabId: currentPlayerId, VirtualCurrency: "GD", Amount: parseInt(userStatsResult.UserStatistics.CurrentGameMoney/2) }); var newScore = ((parseInt(userStatsResult.UserStatistics.PlayerWon) * 2) - (parseInt(userStatsResult.UserStatistics.PlayerLose) + 1)); if (newScore < 0) { newScore = 0; } server.UpdateUserStatistics ({ PlayFabId: currentPlayerId, UserStatistics: { "GameStarted" : 0, "InGame" : 0, "CurrentGameMoney" : 0, "PlayerLose": (parseInt(userStatsResult.UserStatistics.PlayerLose) + 1) }}); } } // Triggered automatically when a Photon room closes // Note: currentPlayerId is undefined in this function handlers.RoomClosed = function (args) { log.debug("Room Closed - Game: " + args.GameId); } // Triggered automatically when a Photon room game property is updated. // Note: currentPlayerId is undefined in this function handlers.RoomPropertyUpdated = function (args) { log.debug("Room Property Updated - Game: " + args.GameId); } // Triggered by calling "OpRaiseEvent" on the Photon client. The "args.Data" property is // set to the value of the "customEventContent" HashTable parameter, so you can use // it to pass in arbitrary data. handlers.RoomEventRaised = function (args) { var eventData = args.Data; var userStatsResult = server.GetUserStatistics ({ PlayFabId: currentPlayerId }); if (eventData[0] == "GameStarted") { server.UpdateUserStatistics ({ PlayFabId: currentPlayerId, UserStatistics: { "GameStarted" : 1, "InGame" : 1 } }); } else if (eventData[0] == "GameOver") { var userInventory = server.GetUserInventory ({ PlayFabId: currentPlayerId }); if (eventData[1] == "Win") { server.AddUserVirtualCurrency ({ PlayFabId: currentPlayerId, VirtualCurrency: "GD", Amount: parseInt(userStatsResult.UserStatistics.CurrentGameMoney/2) }); var newScore = userStatsResult.UserStatistics.PlayerScore + (getGameCategory(userStatsResult.UserStatistics.CurrentGameMoney) * 2); if (newScore < 0) { newScore = 0; } server.UpdateUserStatistics ({ PlayFabId: currentPlayerId, UserStatistics: { "GameStarted" : 0, "InGame" : 0, "PlayerWon": (parseInt(userStatsResult.UserStatistics.PlayerWon) + 1) , "PlayerScore": newScore }}); } else { server.SubtractUserVirtualCurrency ({ PlayFabId: currentPlayerId, VirtualCurrency: "GD", Amount: parseInt(userStatsResult.UserStatistics.CurrentGameMoney/2) }); var newScore = userStatsResult.UserStatistics.PlayerScore - (getGameCategory(userStatsResult.UserStatistics.CurrentGameMoney) * 2); if (newScore < 0) { newScore = 0; } server.UpdateUserStatistics ({ PlayFabId: currentPlayerId, UserStatistics: { "GameStarted" : 0, "InGame" : 0, "PlayerLose": (parseInt(userStatsResult.UserStatistics.PlayerLose) + 1) , "PlayerScore": newScore }}); } updatePlayerLevel(eventData); } }