one more question how do i make my character re spawn at the first checkpoint once i finish the game

this is self explanatory but if you don’t get it i mean something like if you do a level in a game that has checkpoints once you finish it if you want to replay it the level spawns you at the start of the level not at the end checkpoint of the level so how do i do that?

Assuming you are saving out some data that determines you’re at a checkpoint, you just need to clear that or change it to point to the start of the level again.

how do i do that tho if you need to see my scripts to tel me here it is

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameMaster : MonoBehaviour
{
    private static GameMaster instance;
    public Vector2 lastCheckPointPos;
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(instance);
        }
        else
        {
            Destroy(gameObject);
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Checkpoint : MonoBehaviour
{
    private GameMaster gm;
    private playerHitpoint ph;
    // Start is called before the first frame update
    void Start()
    {
        gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
        ph = GameObject.FindGameObjectWithTag("Player").GetComponent<playerHitpoint>();
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            gm.lastCheckPointPos = transform.position;
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerPos : MonoBehaviour
{
    private GameMaster gm;
    private playerHitpoint ph;
    // Start is called before the first frame update
    void Start()
    {
        gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
        transform.position = gm.lastCheckPointPos;
    }
    // Update is called once per frame
    void Update()
    {
        ph = GameObject.FindGameObjectWithTag("Player").GetComponent<playerHitpoint>();
        if (ph.hitPoints <= 0)
        {
            SceneManager.LoadScene("scenelose");
        }
    }
}

and just in case here is my script for the win platform

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class playerWin : MonoBehaviour
{
void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag.Equals("Player"))
        {
            SceneManager.LoadScene("sceneWin");
        }
    }
}

I’d like to point out that if your GameMaster is a singleton, there is no reason to use the FindGameObjectWithTag setting.

That being said, you’re hitting checkpoints and setting the position already. So what you either need to do is when the player finishes is that you set that gm.lastCheckPointPos = to a position at the start of the level or you have a bool to track somewhere that they need to start over again until they hit a checkpoint once more.

So in your win script, just have a position that is the start of your level and set the gm.lastCheckPointPos to that position.

do you mean something like this?

public float firstPosition
void Start()
    {
        gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
    }
void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag.Equals("Player"))
        {
             gm.lastCheckPointPos = firstPosition;
            SceneManager.LoadScene("sceneWin");
        }
    }

or something like that in my win scene script?

if its just adding that gm.lastCheckPointPos = firstPosition; how do i do it, it keeps saying its an error

i just thought of something can i somehow reset the position by making the chekpoint script detect when the win scene is loaded and once its loaded reset the position?

What you have is fine, but lastCheckPointPos is a vector2, so you can’t assign a float to it. You need a vector2 to assign to it.

Sure, you can reset it in the win screen. If you only see the win screen when you clear a level, then you can just have a script reset the lastCheckPointPos in a Start method.

ok i think its almost done im doing it for the lose screen and here is what i have this is PlayerPos script on i put 2 new public floats and a new thing in its void update

public float Xrespawn;
    public float Yrespawn;
 void Update()
    {
        ph = GameObject.FindGameObjectWithTag("Player").GetComponent<playerHitpoint>();
        if (ph.hitPoints <= 0)
        {
            Instantiate(LEGEND, new Vector3(Xrespawn, Yrespawn), 0);
            SceneManager.LoadScene("scenelose");
        }
    }

but the 0 is underlined red so what do i do to fix it? also i think the 0 is for z but somehow its underlined red

Your 0 is outside the vector3

Instantiate(LEGEND, new Vector3(Xrespawn, Yrespawn, 0));

oh ok thank you
edit: um it didnt work