Why is the player not moving with a moving platform in unity?

If I am running the game in build mode, and when I jump onto the platform, the player moves along with it. But whenever the player dies and goes inactive, resets position and goes active again, it then doesn’t work. Weirdly enough, when I am in the attacking mode, it works, but when I am in the regular moving mode, it doesn’t.

Here are the scripts for my platform:

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

public class PlatformMovement : MonoBehaviour
{
    public int PlatformDirection = 0;
    public int MoveSpeed;
    void Update()
    {
        if (PauseMenu.Paused == 0)
        {
            if (PlatformDirection == 0)
            {
                transform.Translate(Vector3.forward * MoveSpeed * Time.deltaTime);
            }
            if (PlatformDirection == 1)
            {
                transform.Translate(Vector3.back * MoveSpeed * Time.deltaTime);
            }
        }
    }
    void OnCollisionEnter (Collision col)
    {
        if(col.gameObject.name == "Wall")
        {
            if (PlatformDirection == 0)
            {
                PlatformDirection = 1;
            }
            else
            {
                PlatformDirection = 0;
            }
        }
   }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlatformDetector : MonoBehaviour
{
    public GameObject Player;
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject == Player)
        {
            Player.transform.parent = transform;
        }
    }
    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject == Player)
        {
            Player.transform.parent = null;
        }
    }
}

And the script for my player:

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

public class PlayerController : MonoBehaviour
{
    public float _moveSpeed;
    public float _gravity;
    public float _jumpSpeed;
    public float _bounceSpeed;
    public static int movemode;
    public GameObject Camera;
    public Animator animator;
    public AudioSource audioSource;
    public AudioClip JumpSound;
    public AudioClip BoingSound;
    public AudioClip HitSound;
    public static int OnIce;

    private CharacterController _controller;
    private Rigidbody rb;
    private float horizontalInput;
    private float verticalInput;

    public static float _directionY;
    
    // Start is called before the first frame update
    void Start()
    {
        _controller = GetComponent<CharacterController>();
        audioSource = gameObject.GetComponent<AudioSource>();
        movemode = 0;
        PauseMenuController.ExitingLevel = 0;
    }

    // Update is called once per frame
    void Update()
    {
        if (movemode == 0)
        {
            _moveSpeed = 5f;
            _gravity = 9.81f;
            _jumpSpeed = 4f;

            if (OnIce == 0)
            {
                horizontalInput = Input.GetAxis("Horizontal");
                verticalInput = Input.GetAxis("Vertical");
            }
            if (OnIce == 1)
            {
                horizontalInput = Input.GetAxis("HorizontalIce");
                verticalInput = Input.GetAxis("VerticalIce");
            }

            Vector3 direction = new Vector3(horizontalInput, 0, verticalInput);
            direction = Camera.transform.TransformDirection(direction);
            if (_controller.isGrounded)
            {
                    if(Input.GetButtonDown("Jump"))
                    {
                        audioSource.PlayOneShot(JumpSound, 1);
                        _directionY = _jumpSpeed;
                    }
            }
            if (!_controller.isGrounded)
            {
                _directionY -= _gravity * Time.deltaTime;
                direction.y = _directionY;
            }
            else
            {
                _directionY -= 0 * Time.deltaTime;
                direction.y = _directionY;
            }

            _controller.Move(direction * _moveSpeed * Time.deltaTime);

            animator.SetBool("isWalking", verticalInput != 0 || horizontalInput != 0);
            animator.SetBool("isGrounded", _controller.isGrounded == true);
            animator.SetBool("Attacking", movemode == 3);
            animator.SetBool("Swimming", movemode == 1);
            animator.SetBool("LevelComplete", movemode == 4);
        }
        if (movemode == 1)
        {
            _moveSpeed = 3f;
            _gravity = 4f;
            _jumpSpeed = 1.5f;

            float horizontalInput = Input.GetAxis("Horizontal");
            float verticalInput = Input.GetAxis("Vertical");

            Vector3 direction = new Vector3(horizontalInput, 0, verticalInput);
            direction = Camera.transform.TransformDirection(direction);

            if(Input.GetButtonDown("Jump"))
            {
                _directionY = _jumpSpeed;
            }
                _directionY -= _gravity * Time.deltaTime;
                direction.y = _directionY;

            _controller.Move(direction * _moveSpeed * Time.deltaTime);

            animator.SetBool("Swimming", movemode == 1);
            animator.SetBool("Attacking", movemode == 3);
        }
        if (movemode == 3)
        {
            animator.SetBool("Attacking", movemode == 3);
        }
        if (movemode == 4)
        {
            animator.SetBool("LevelComplete", movemode == 4);
        }
    }
    void OnTriggerEnter (Collider col)
    {
        if(col.gameObject.name == "Spike")
        {
            if (Pos_reset.invincibilityframe > 2)
            {
                HealthCounter.Health -= 1;
                if (HealthCounter.Health > 0)
                {
                        audioSource.PlayOneShot(HitSound, 1);
                        _directionY = _jumpSpeed;
                }
                Pos_reset.invincibilityframe = 0;
            }
        }
        if(col.gameObject.name == "Trampoline")
        {
            audioSource.PlayOneShot(BoingSound, 1);
            _directionY = _bounceSpeed;
        }
    }
}

Any ideas of why this is happening?

New contributor

Ooblue365 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật