Displaying the y value score,Displaying the score of the Y value

Please help, what can i do? i am newbie to coding (1 week)
,Imade a doddle jump like game and want to add score to it.
I want the score to display the Y position of the player.
Here is my code

ScoreScript

using UnityEngine;
using UnityEngine.UI;
public class scorescript : MonoBehaviour
{


    public static int ScoreValue = 0;
     
    Text score;


    void Start()
    {
       
        score = GetComponent<Text>();
    }    

    
    void Update()
    {

        score.text = "Score  " + ScoreValue;
    }
}

Player script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class rigidbody : MonoBehaviour
{
    private Rigidbody rb;
    

    void Start()
    {

        rb = GetComponent<Rigidbody>();
        Vector3 v3Velocity = rb.velocity;

        GetComponent<scorescript>();
    }

    void Update()
    {
        

            scorescript.scoreValue += rb.velocity.y;
        
    }   

}

Whats wrong, please help me i am newbie to unity.

Since you’re new to programming I’d like to go over your code a bit more than just making it work, so you don’t develop bad habbits. I hope you’re ok with that.

Lets start with the Player script:

First, class names start with a upper case letter and try not giving your classes names that do already exist.

I would suggest calling your player script actually just Player.

public class Player : MonoBehaviour
{
    ... 

I would remove any dependencies on your score script from the player calss so ‘Player.cs’ can work independently of the score script without causing errors or bugs.

That means removing GetComponent<scorescript>(); from Start() and removing scorescript.scoreValue += rb.velocity.y; from Update() .

Make the ‘rb’ field public so you can access it from the other script. public Rigidbody rb;

Now to the Score script:

Same rule for its name, first letter is upper case and i personally would give it a more descriptive name. Let’s call it PlayerScore for now.

public class PlayerScore : MonoBehaviour
{
    ...

You can get completely rid of the public static int ScoreValue = 0; field.

But just so you know: variable names always start with lower case and to declare this one variable field as static is completely unnecessary.

Make a field to reference your Player class instead. It can be private because it will be used just in this class itself.

private Player player;

And in the Start() method set the player reference;

void Start ()
{
    player = GetComponent<Player>();
    ...

Now in your Update() method just do:

score.text = "Score " + player.rb.position.y.ToString();

Your PlayerScore script will now automatically, every frame, access the Player script, read its rigidbodys Y position and display it as text. .ToString() is needed to convert the float it recieves into an actual string value.

Hope this helps.