need help with bowling game

Hi I am making a bowling game for college. I am trying to work on the score. Once the ball knocks down say 4 pins, I want the game to say, 'you got four" and restart so that the player can try knock down the rest. If they get a strike, I want eh game to say “You got a strike” and reload the level.

However currently, when the ball hits any pin, even only knocks down one pin the score goes straight to zero and the level restarts. Can anyone help please. Here is the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class PinDetection : MonoBehaviour
{
    public int pins = 10; //number of pins sper game
    public Text scoreText;

    // Use this for initialization
    void Start () {
        scoreText.text = "You Scored: " + scoreText.ToString ();
       
    }
   
    // Update is called once per frame
    void Update ()
    {
        //Vector3 fwd = transform.TransformDirection(Vector3.forward);

        if (transform.up.y < 0.5f)
        {
            Debug.Log("Yes");
            pins--;
        }

        if (pins <= 0)
        {
            Debug.Log ("Strike");
            Time.timeScale = .25f;
            SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex);

            scoreText.text = "Strike";
        }
        else
            if(pins>0 || pins<=10)
            {
                scoreText.text = "You scored" + pins;

            }
    }
}

Unfortunately, I don’t even know what in your scene has this script, but since you are running this in update, you’re going to hit the restart right away.

As soon as your transform.up.y < .5f is true, you’re subtracting 1 from pins. Since you could hit update several times a second, you’ll hit this multiple times which means eventually your second if check is true. This will all happen within 1 second, which is why you’re getting a quick restart.

Just for the record I have this script attached to each of the ten pins

Are you saying put that in its own Class then? Tks for reply

Here is probably what I would do. I would have a Manager type script that would have a list of all the pins. When a player rolls the ball, you need some way to detect when it’s finished knocking down pins (maybe after the ball hits a trigger collider start a timer to give all pins a chance to fall). Then, loop through all pins to check the position (if that is the best way to determine if they are knocked over) and then subtract for each knocked over pin. Then after the loop you’ll display the score.

Note that you’re not going to have this script on each pin…Another problem with that is each pin is tracking that there are 10 standing pins. Even if you knocked down 5, each pin would only know that it was knocked down, so your score would be 1 pin knocked down only. You’ll want to go with a manager script instead.

Christ ok, I will have to think about how I will even do that. Thanks for the suggestion though, I appreciate it.