Help..... playerprefs is not working why?

Hi everyone, I am creating a visual novel, and I created a playerprefs to save the dialogue, the position and pose of the character so when you load the game appears the exact dialogue where the player was last time, but when loading only appears the scene where the player was the last time and no dialogue or character pose

public void OnGUI()
    {

        if (SceneManager.GetActiveScene().name == "Scene1")
        {
               PlayerPrefs.SetString("dialogo", dialogue);
                PlayerPrefs.SetString("name", characterName);
                PlayerPrefs.SetString("position", position);
                PlayerPrefs.SetInt("pose", pose);
            PlayerPrefs.SetInt("line", lineNum);      
                             
                PlayerPrefs.Save();
                Debug.Log("save");

          

            level = 1;
            PlayerPrefs.SetInt("level", level);
            PlayerPrefs.Save();
            Debug.Log("guardado" + level);
        }

        if (SceneManager.GetActiveScene().name == "Scene3")
        {

            level = 3;
            PlayerPrefs.SetInt("level", level);
            PlayerPrefs.Save();
            Debug.Log("guardado" + level);
        }


        if (SceneManager.GetActiveScene().name == "Scene2")

        {
            bool botton = GUI.Button(new Rect(200, 80, 80, 50), "load");
            if (botton)
            {
                level = PlayerPrefs.GetInt("level");
                if (level == 1)
                {
                    SceneManager.LoadScene("Scene1");
                    lineNum = PlayerPrefs.GetInt("line");
                    transform.position = new Vector3(PlayerPrefs.GetFloat("x"), PlayerPrefs.GetFloat("y"), PlayerPrefs.GetFloat("z"));
                    transform.position = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z);
                    dialogue = PlayerPrefs.GetString("dialogo");
                    characterName = PlayerPrefs.GetString("name");
                    position = PlayerPrefs.GetString("position");
                    pose = PlayerPrefs.GetInt("pose");
                    lineNum++;
                   
                  
                   
                }
            }
        }
    }

OnGUI has some weird performance problems and is outdated, so consider switching to the new UI started in Unity 4.6.

When using OnGUI you don’t want to have a lot of calculations, you could create an external function (void SaveScene(string sceneName)) and then only call on them when needed and not every time OnGUI runs - the reason being OnGUI is running constantly like Update so it should have as little as possible (Like only your conditions and the GUI.Button stuff needs to be in OnGUI.

As for why your code is not working, try making sure all scenes are properly named to match your strings. I have not personally used PlayerPrefs much, but I’ve only heard bad things about it as far as compatibility later on. It’s a lot more work but you’d be better off creating your own FileManager class to save/load files to store your player info and then call on that when you need to save/load stuff.

I’ve looked through your code a few times now and cannot figure out what the error is without seeing further code, but try writing a function (void SaveScene(levelNum or SceneName, and LoadScene(levelnum,sceneName)) that will save your scene for you any time you call it, this will help you figure out where your error is.
One other thing is your loading “position” as a string when it’s actually a vector3, this may not matter if you extract the data from it some other way

Also look into loading Scenes as Additive Unity - Scripting API: Application.LoadLevelAdditive
That way the character can be preserved between scenes and not have to worry about keep tracking of variables because it’ll be in the Player’s GameObject. What you do is create a ‘Playe Scene’ that is empty except for the player, camera, everything that needs to exist at all times, and then create scenes for every place and Load as ‘Additive’ and then you can keep the player data at all times. Upon looking at that it also says SceneManager.LoadScene is obselete, and you’re better off using LoadLevel/Additive

SceneManager.LoadScene("Scene1");
lineNum = PlayerPrefs.GetInt("line");
...

I think that is a bit dangerous coding practise. If you LoadScene(), expect that everything in current scene ends right there on that line. Move the code to Start() of the scene instead.

Also in your code there if you have Scene1 or Scene3 active, it would be repeatedly spam-saving like 60 times per second.