Rigidbody not sleeping?

Godot Version

4.3

Question

I am new to Godot and is learning from Tutemic’s code architecture tutorial, but I couldn’t get the engine to detect if all pool balls have stopped moving (around 6:12:00 mark of https://www.youtube.com/watch?v=k0vZbIclXjE&t=22318s). In my case, the console has an output overflow where it keeps printing num_ball_moving as 15 and then 16 again and again after running the main scene. Is this because the Rigidbodies are not sleeping? If so, is there a workaround? (or is it because I have typed something wrong?)

Here is my ball.gd to make things clearer
class_name ball
extends RigidBody3D

@export var _texture: Texture2D
const BALL_RADIUS := 0.027
const BALL_DIAMETER := BALL_RADIUS * 2
static var num_ball_moving : int = 0

var _ball_num = 0
var ball_type: Enums.BallType = Enums.BallType.CUE_BALL

func _ready():
if not self.sleeping:
ball.num_ball_moving += 1
_apply_new_material()

func _integrate_forces(state: PhysicsDirectBodyState3D) → void: #Use this for physics instead of
#PROCESS FUNCTION
self.linear_velocity.y = min(ball.BALL_DIAMETER, self.linear_velocity.y)
#let Y velocity be itself unless it exceed BALL_DIAMETER

func setup_balls(ball_num: int, ball_x: float, ball_z: float):
_ball_num = ball_num

if ball_num == 8:
	self.ball_type = Enums.BallType.EIGHT_BALL
elif ball_num == 0:
	self.ball_type = Enums.BallType.CUE_BALL
elif ball_num < 8:
	self.ball_type = Enums.BallType.SOLIDS
else:
	self.ball_type = Enums.BallType.STRIPES

self.position.x = ball_x
self.position.z = ball_z

_texture = load("res://Ball Textures/" + str(ball_num) + ".jpg")
_apply_new_material()

func _apply_new_material():
var new_material = StandardMaterial3D.new() #make new material
new_material.albedo_texture = _texture #Assign the new material to whatever texture is on the exported var
$Ballmesh.material_override = new_material #Apply new material
print (“Coloring happened.”)

func _on_sleeping_state_changed() → void:
if self.sleeping:
ball.num_ball_moving -= 1
else:
ball.num_ball_moving += 1

print("current balls moving ", num_ball_moving)