Hello. I tried to make a score and high score for my game by using Player Prefs but got the error CS0029 in the console. Here is my code : Code (CSharp): using UnityEngine; using UnityEngine.UI; public class Score : MonoBehaviour { public Transform player; public Text scoreText; public Text highscoreText; void Start() { highscoreText.text = PlayerPrefs.GetInt("HighScore", 0).ToString(); } void Update() { int number = player.position.z.ToString("0"); scoreText.text = number.ToString(); if (number > PlayerPrefs.GetInt("HighScore", 0)) { PlayerPrefs.SetInt("HighScore", number); highscoreText.text = number.ToString(); } } } Here is also the error message: Assets\Scripts\Score.cs(17,22): error CS0029: Cannot implicitly convert type 'string' to 'int' Thank you in advance.
Line 17, char 22 is what the error points to. But to be clear, you are doing ToString, but trying to assign the value to an int. ToString will convert player.position.z into a string not an int.
You were already given the answer in the other topic that you posted in: https://forum.unity.com/threads/error-code-cs0029.898880/#post-6852347 And you already said in that one that the solution provided works, so why have you put your script back to the old broken code again? On line 17 you have converted the z value to a string but are trying to put it into an integer.