train problems

In the game i am currently working on i have a train system that serves to take the player across an island, the train is moving on a loop through the animation system, the problem is the player wont stay on the train i have tried everything from coliders to fixed joints nothing seems to work this is the current code of the train:

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

public class train_board_confusion : MonoBehaviour {

public GameObject train;
public GameObject item;

// Use this for initialization
void Start () {
   
    

}


// Update is called once per frame
void FixedUpdate () {

    

     item.transform.parent = train.transform;

}

void OnTriggerEnter(Collider other)
{

    item = other.gameObject;

}

}

the current error is saying it cant change the parent of a prefab, please help im relatively new to game development and c# so im probably missing something stupid.

With the animation, I’m guessing you’re just changing it’s position. If that’s the case, the only way I could think of to have the player move with the train is if you set the player’s position as well. As for your error, I’m assuming that item is a prefab. If you want to keep it this way, I’d suggest instantiating the item first, which you can read up on how to do here. Basically, you just make a new local variable and set it to the instantiation like this: GameObject newItem = Instantiate<GameObject>(item);.