question

Riccardo Iengo avatar image
Riccardo Iengo asked

Can't execute cloud script on player added title!

Hey guys, I want to set a BestTime value of 0 when a player starts the game for the very first time.
here's my code for the cloud

handlers.SetPlayerValues = function (args, context) {
server.updateUserDataResult({
PlayFabId: currentPlayerId,
Data: { "BestTime": "0" }
})
};

Can someone tell me what am I doing wrong? Thanks

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

The correct API name is “UpdateUserData” not “updateUserDataResult”, you can modify the method name to make it work.

Besides, in your design, the K/V pair { "BestTime": "0" } should be the Read-Only Data that can’t be modified by users, is it right? If so, we would suggest you use the UpdateUserReadOnlyData instead of using the UpdateUserData. Since the User Data can be written by users, storing the data like “personal best records” in it will make cheating easier. You can check this documentation -- How to modify read-only or internal player data from CloudScript - PlayFab | Microsoft Docs to learn about how to set Read-only Player Data using CloudScript.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Riccardo Iengo avatar image Riccardo Iengo commented ·

@Sarah Zhang one more thing! What If I want to replace the old Best Time with the new Best Time? The example function from your link (How to modify read-only or internal player data from CloudScript - PlayFab | Microsoft Docs) would still be valid or should I execute something different?

0 Likes 0 ·
Riccardo Iengo avatar image Riccardo Iengo commented ·

Thanks! This is what I was looking for

-1 Like -1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.