Heloo help me pls I am a beginner

I need find out error why my highscore still add numbers into infinity because are having to highscore + score

my script :

static var score = 0; //current score
//combined total of players score
var highscore = 0; //highest score player has gotten

var scoretext : GUIText;
var MenuScore : GUIText;

function Start(){
highscore = PlayerPrefs.GetInt(“High Score”);
}

function Update()
{
scoretext.text = score + “”; //display score
MenuScore.text = highscore + “”;

if(score > 1 ) //when player dies set highscore = to that score
{
highscore = highscore + score ;

PlayerPrefs.SetInt(“High Score”, highscore );

Debug.Log("High Score is " + highscore );

}

}

If i understand you correctly i think your problem is your if statement, your always increasing your highscore by adding score to it…

what if instead you did something like…

if (score > highscore)
{
highscore = score;
}

I want to high score was menu score

static var score = 0; //current score
//combined total of players score
var menuscore = 0; //highest score player has gotten

var scoretext : GUIText;
var MenuScore : GUIText;

function Start(){
menuscore = PlayerPrefs.GetInt(“Menu Score”);
}

function Update()
{
scoretext.text = score + “”; //display score
MenuScore.text = menuscore + “”;

if(score > 1 ) //when player dies set highscore = to that score
{
menuscore = menuscore + score ;

PlayerPrefs.SetInt(“Menu Score”, menuscore );

Debug.Log("Menu Score is " + menuscore );

}

}

it would help if you put code in between code brackets so it would be easier to read, at the top of the post editor click the button to the left of the save icon and then click code from the drop down

static var score = 0; //current score
//combined total of players score
var menuscore = 0; //highest score player has gotten
var scoretext : GUIText;
var MenuScore : GUIText;
function Start(){
menuscore = PlayerPrefs.GetInt(“Menu Score”);
}
function Update()
{
scoretext.text = score + “”; //display score
MenuScore.text = menuscore + “”;

 if(score > 1 ) //when player dies set highscore = to that score
 {
      menuscore = menuscore + score  ;
  
     PlayerPrefs.SetInt("Menu Score", menuscore );
  
     Debug.Log("Menu Score is " + menuscore );

 } 

}

Yeah i think your problem is the if statement.
Right now your saying “Take player score and add it to the menu score”

for instance, first time you play, menu score will be 0… lets say you get a score of 50…
now menu score is 50… you play again and you get a score of 100, now the menu score will be 150… and so on.

to fix this you need to stop adding to menu score.
instead you want to reset the menu score ONLY if the player score is higher then menu score.

so IF player score is greater then menu score, set menu score to player score.

if (score > menuscore)
{
     menuscore = score;
}

if this does not help, then I’m not sure how to fix your problem.

I want to Main Menu score not menu score sorry my english is weak

could you can help me

thus I have it thought

score :

static var score = 0; //current score
//combined total of players score
var menuscore = 0; //highest score player has gotten
var scoretext : GUIText;
var MenuScore : GUIText;

function Start(){
menuscore = PlayerPrefs.GetInt("Menu Score");
}
function Update()
{
 
     scoretext.text = score + ""; //display score
     MenuScore.text = menuscore + "";
    
     if(score > 1 ) //when player dies set highscore = to that score
     {
          menuscore = menuscore + score  ;
        
         PlayerPrefs.SetInt("Menu Score", menuscore );
        
         Debug.Log("Menu Score is " + menuscore );
    
     }   
    
}
////////////////////////////////////////////////
main menu script :

#pragma strict

var menuscore = 0;
var MenuScore : GUIText;

function Start () {
menuscore = PlayerPrefs.GetInt("Menu Score");
}

function Update()
{
   
     MenuScore.text = menuscore + "";
    
     }

////////////////////////////////////////////////
and touch to game object :

function Update ()
     {
       if (Input.touchCount > 0)
       {
           var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
           var hit : RaycastHit;
        if (Physics.Raycast (ray, hit))
       {
               Debug.Log(" You just hit " + hit.collider.gameObject.name);
        if(hit.collider.tag == "Part")
        {
         ScoreScript.score += 1;
        }
       }
      }
     }

I do not want it thus

  • if (score > menuscore)
  • {
  • menuscore = score;
  • }

Im not sure what your problem is then… Didn’t you say your Main Menu Score keeps increasing to infinity?.. thats because you keep adding to it every time… sorry i must be misunderstanding your problem.

sorry my english is weak me I want only score that was credited on main menu script score

hmmm so the script is on another game object your trying to access? that would be something like.

mainmenu = GameObject.find(“game object name”).GetComponent();

x = mainmenu.score

sorry that is the best i can do, if that does not help then you will have to wait for somebody else to respond.

So, first. You say it does not work that way but in every second post you say you want it that (not working) way?

The first problem is that you increase the Highscore in the Update() function. If the Player has a higher score then 1 it will be added … the Update() function gets called EVERY frame, which means you add the score roughly 50 times per second (or even more depending on your framerate).

You should stick to the advice people in here gave before. Check if a higher score than the highscore was scored. And then (ONLY then) update the highscore.

I mean … why would you even add the current score to the highscore? When I score 50 first it is my highscore. I score 100 in the second attempt which makes my Highscore 100. With your logic it is 150, because you just add it, which is well … not really how a highscore works.

So the best advice is: Follow the advices given here instead of saying you want your obvioulsy not working solution.

Ok I have it finished score , high score , and total score .
Thank all Men :slight_smile:

Will you help me more PLEASE?
with JavaScript: the android when I click on Gameobject so we’ll credit score

Ok I have it finished score , high score , and total score .
Thank all Men :slight_smile:

Will you help me more ?
with JavaScript: the android when I click on more Gameobject so we’ll credit score

android one click on GameObject set to score and total score

var CickScore : float;

ScoreScript.score += CickScore;
ScoreScript.totalscore += CickScore;