> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Modify read-only or internal player data via CloudScript

> Safely update read-only and internal PlayFab player data from CloudScript using server.UpdateUserInternalData with C# and JavaScript sample code.

Player data is accessible from CloudScript if you require it for your title.

For more information about using CloudScript, see [CloudScript quickstart](/services/playfab/live-service-management/service-gateway/automation/cloudscript/quickstart).

The C# Sample in this topic are written for the Unity SDK. The Unity SDK uses an event driven model to handle asynchronous tasks. To run the sample code using the C# SDK, you must modify the code to use an async Task model. Methods that must be modified have Async append to the method name in the signature. For example, SetObject in the Unity SDK becomes SetObjectAsync in the C# SDK. For more information, see [Asynchronous programming with async and await](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/).

## CloudScript code example

You must be careful to ensure the security of your server API calls in CloudScript. The following code demonstrates modifying a piece of read-only player data from CloudScript safely.

```javascript theme={null}
function IncrementReadOnlyUserData(args) {
  var playerData = server.GetUserInternalData({
        PlayFabId: currentPlayerId,
        Keys: ["ReadOnlyTest"]
  });

  var prevCount = "0";
  var nextCount = "1";
  try {
    prevCount = playerData.Data["ReadOnlyTest"].Value;
    var prevInt = parseInt(prevCount, 10);
    if (prevInt != prevInt) {
      prevInt = 0;
      nextCount = (prevInt + 1).toString();
    }
  } catch (e) {
    prevCount = "0";
    nextCount = "0";
  }

  var updateUserDataResult = server.UpdateUserInternalData({
    PlayFabId: currentPlayerId,
    Data:
        {
          "ReadOnlyTest": nextCount
        }
  });
}
```

## C# code example

As explained in the CloudScript quickstart, you can call the following logic from the client.

```csharp theme={null}
public void CloudIncrement() {
    PlayFabClientAPI.ExecuteCloudScript( new ExecuteCloudScriptRequest {
        FunctionName = "IncrementReadOnlyUserData"
    },
    result => Debug.Log("CloudScript call successful"),
    error => {
        Debug.Log("CloudScript call failed");
        Debug.Log(error.GenerateErrorReport());
    });
}
```


## Related topics

- [Quickstart Player Data](/services/playfab/player-progression/player-data/quickstart.md)
- [Using CloudScript actions with PlayStream](/services/playfab/data-analytics/acting-data/action-rules-using-cloudscript-actions-with-playstream.md)
- [CloudScript](/services/playfab/live-service-management/service-gateway/automation/cloudscript/index.md)
- [Use player publisher data to reward multi-title play](/services/playfab/player-progression/player-data/using-player-publisher-data.md)
- [Using publisher data](/services/playfab/live-service-management/game-configuration/titledata/using-publisher-data.md)
