How to make an efficient crusher system?

  1. What do you want to achieve? I need to create a efficient crusher system.

  2. What is the issue? I didn’t find a good way to do it

  3. What solutions have you tried so far? I made my own using the position of the head or the PrimaryPart of the character but it is very unpredictable.

My Code:

local MainPartReference = Char.Head
while true do
	task.wait()
	if Char.Humanoid:GetState() ~= Enum.HumanoidStateType.Swimming then -- even if i put this condition, it is too unpredictable and does damage when it is not necessary
       print(MainPartReference.Position.Z) -- never used the z coordinate because i realized how inefficient the code was
	   if MainPartReference.Position.Y < 1 or MainPartReference.Position.X < -247 then -- i was testing the x coordinate
		  if Char.Humanoid.Health <= 0 then
			 if Char:FindFirstChild("AtoClient") then
				Char.AtoClient.Stances.GibsOnDeath.Value = true -- custom death i made
				break
			 end
		  else
			  task.wait(.2) -- cooldown
			 DamageHandler:SetDamage(ReplicatedStorageService.AtoEngine.api.DamageFeedback.WorldObjects, Char.Humanoid, "physics", nil, Char:GetScale() * 10, 1, 1, true) -- custom damage function i made
		  end
	   end
	 end
end