OnCollisionEnter issues

I cannot for the life of me figure out what I am doing wrong. I have gone through several different tutorials and walkthroughs, but nothing seems to work. I want a “Ceiling” to eventually crush the “Player” if they don’t make it to the exit in time. The player is tagged as “Player” and has a kinematic rigidbody attached. The ceiling has the following script attached.

 function OnCollisionEnter (collision : Collision) {
     
     if(collision.gameObject.tag == "Player"){
     
         Destroy(gameObject);
         
 }
 
 }

Can anyone help me out with this? I know it has to be something simple…

I understand that you want to destroy the player object and you said that “The ceiling has the following script attached”, so when you do “Destroy(gameObject);” you are destroying the ceiling (if the code works). Change it to “Destroy(collision.gameObject);” and that should work, let me know if that solves the issue!

This code will destroy the ceiling and also your code.
you found the player by tag but the destroy action will not be applied to that player unless you correctly specify it.

  function OnCollisionEnter (collision : Collision) {
      
      if(collision.gameObject.tag == "Player"){
      
          Destroy(collision.gameObject);
          
  }
  
  }

Destroy does NOT destroy the gameObject immedietly, it just tells the engine to destroy the game object whenever the engine wants to!

Try this instead:

gameObject.SetActive(false);
Destroy(gameObject);