'Vector3' does not contain a definition for 'transform'

Hey guys! I’m having some problems with my code, I review it several times but couldn’t find where it’s wrong. This code is for a player movement from an asset.

FirstPersonMovement.cs(28,44): error CS1061: ‘Vector3’ does not contain a definition for ‘transform’ and no accessible extension method ‘transform’ accepting a first argument of type ‘Vector3’ could be found (are you missing a using directive or an assembly reference?)

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


public class FirstPersonMovement : MonoBehaviour
{
    public float speed = 5;

    [Header("Running")]
    public bool canRun = true;
    public bool IsRunning { get; private set; }
    public float runSpeed = 9;
    public KeyCode runningKey = KeyCode.LeftShift;
    static public bool dialogue = false;
    public Respawnpos respawnpos; //vector3 reference from another script
    public Vector3 Spawn;
    Rigidbody rigidbody;
    /// <summary> Functions to override movement speed. Will use the last added override. </summary>
    public List<System.Func<float>> speedOverrides = new List<System.Func<float>>();



    public void Start()
           {
        // Get the rigidbody on this.
        rigidbody = GetComponent<Rigidbody>();
        Spawn = respawnpos.respawnPosition.transform.position;
        //respawnPosition = gameManager.spawnpoint.transform.position;
           }



    void FixedUpdate()
    {
        if (!dialogue)
        {
            IsRunning = canRun && Input.GetKey(runningKey);

            // Get targetMovingSpeed.
            float targetMovingSpeed = IsRunning ? runSpeed : speed;
            if (speedOverrides.Count > 0)
            {
                targetMovingSpeed = speedOverrides[speedOverrides.Count - 1]();
            }

            // Get targetVelocity from input.
            Vector2 targetVelocity = new Vector2(Input.GetAxis("Horizontal") * targetMovingSpeed, Input.GetAxis("Vertical") * targetMovingSpeed);

            // Apply movement.
            rigidbody.velocity = transform.rotation * new Vector3(targetVelocity.x, rigidbody.velocity.y, targetVelocity.y);
        }

    }
}

There’s another script that is referenced in the first one

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

public class Respawnpos : MonoBehaviour
{
    public GameObject player;
    public GameObject spawn;
    public Vector3 respawnPosition;


    // Start is called before the first frame update
    public void Start()
    {
        respawnPosition = player.transform.localPosition;
    }

    public void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.CompareTag("Player"))
        {
            respawnPosition = this.transform.localPosition;
        }
    }

}

FirstPersonMovement.cs(28,44): means line 28 around column 44.

28. Spawn = respawnpos.respawnPosition.transform.position;

'Vector3' does not contain a definition for 'transform'

Your statement is using .transform but the thing to the left (respawnpos.respawnPosition) is a Vector3. There is no transform unless you’re talking about a component or gameobject. Since you ultimately are trying to figure out a Vector3 for Spawn, I think you just want this.

28. Spawn = respawnpos.respawnPosition;

It would be good to go through a basic C# course to get more comfortable with understanding variable types.

The error says exactly what the problem is- there’s no such thing as Vector3.transform.

Here is the API for transform:

If respawnpos.respawnPosition is a position then just use that. respawnpos.respawnPosition.transform.position. doesn’t make any sense.

Thanks for the replies guys! I’m still new to coding and taking some classes, I was wondering why it wasn’t working since in class we did a similar code, I need study more lol. Anyway, thanks for helping me out!