Save Info to new scene

Started by xraybeesx · 3 months ago · 2 replies · 101 views

#1
xraybeesx
Member
JoinedApr 2026 Posts19 Score1,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!!
edited 3 months ago#2
xraybeesx
Member
JoinedApr 2026 Posts19 Score1,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
Austin
Member
JoinedOct 2021 Posts156 Score2,540
just save it to a component and then set that components gameobject flag to DontDestroyOnLoad
https://sbox.game/api/Sandbox.GameObject/Flags
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.