Custom Health Script problems

So heres what I’m working on

This is a Health script I’ve been working on. The idea is that when damaged it will wait collective.Healpace.Value before healing the player. And if the player is attacked during the script healing than the healing process gets cancelled and the timer restarts. Pretty basic

However I’m running into some trouble with one more feature I want to add to this. I want to make it so if the Health.Value is greater than the maxCheck than it’ll start removing health until it reaches its max. It sounds simple but I’ve been running into alot of errors and bugs that either end up breaking the healing process, or causing for “Maximum event re-entrancy depth exceeded for NumberValue.Changed” errors. Which is not what I’m looking for

If you have any ideas that may help. Please reply. Also I’m considering using RunService but at the moment I don’t really want to do that because the script is a serversided and I want to try and build my scripts for performance

Could you format the code better please, very hard to read, not really able to pick out what the issue is.

Looked through the code and found something that might help, you might wanna try re-writing it and using the docs to guide you. Your syntax is far off of what it should be, and the overall method isn’t efficient.

How would I do that? I’m not exactly sure how

Put it in a code box and set the indentations correctly, or upload an image of the script. It would also be helpful if you could provide any errors you might be having.