Ray cast is a huge problem. Causing most of the lag. I don’t know if there’s another option. Since it’s a tower defense and everything uses ray-cast to check for targets.
try using coordinate detection to detect if they are at a certain position
I looked in your code and failed to find anything that has raycasts in it. Could you please find what is sending them? Then optimization could be much easier to problem solve.
I made a semi-fix, to where now it checks if there is an enemy alive able to be hit, but that doesn’t change much.
And the eater is constantly detecting for plants to eat.