Save Info to new scene

Started by xraybeesx 3 posts 98 views

Reply on sbox.game
  1. #1
    xraybeesx 1,160
    I am trying to save the player score into a new scene,  my score system works fine you collect items you gain points, but when I load the next scene/level it resets to 0, I'm not sure how to go about carrying this info over from scene to scene.... I tried making a game manager script, but that just resets with the new scene load as well.

    Any help would be appreciated!!
  2. edited Jun 2026 #2
    xraybeesx Started this 1,160
    I figured it out,

    I made a c# public class called ScoreManager:

    using Sandbox;
    
    
    public static class ScoreManager
    {
    	
    	public static int CurrentScore { get; set; }
    }
    Then on my player controller I do this:

    protected override void OnUpdate()
    {
    	points = ScoreManager.CurrentScore;
    }
    And I add and subtract my points to the ScoreManager rather than directly to the players points:

    public void Addpoints( int Amount )
    {
    	ScoreManager.CurrentScore += Amount;
    		
    }


    edited:
    The Score Manager just lives in your CODE folder or wherever you keep your scripts, no need to add it to your scene.
  3. #3
    Austin 2,540
    just save it to a component and then set that components gameobject flag to DontDestroyOnLoad
    https://sbox.game/api/Sandbox.GameObject/Flags