Based on the limited information you've provided, my guess is a null pointer exception in the script.
From the KinematicBody2D docs (assuming your player, and/or the script your showing us, is a KinematicBody2D):
The body will stop if it collides. Returns a KinematicCollision2D, which contains information about the collision when stopped, or when touching another body along the motion.
From the KinematicCollision2D docs (discussing move_and_collide
results):
If a collision is detected, a KinematicCollision2D object is returned.
It seems move_and_collide
doesn't always return a value, and will only actually give you an object if there is a collision. You should add a check that you actually got an object before trying to access that object's properties. If you got no result, assume there is no collision.
Based on your comment providing the error output, this is exactly the issue.
It is a kinematic body 2d. the error is "Invalid get index 'collider' (on base: 'null instance')
The move_and_collide
function only returns an object when there is a collision. Otherwise it returns null. It is called every frame, and there is not always a collision. You need to add a null check to verify it actually returned something before checking what kind of collision it was.
To fix avoid this particular error, change your if condition to the following, in order to make sure you only attempt to access properties on the collision object if it actually exists.
if collision != null:
if collision.collider.name == "Spikes Tilemap":
print("collided")
# any other code that relies on using collision