Well the code i given you is not a copy paste magic ofcourse.

Insert it on the right place.

Ex.

In the upper place of thread that make sure the whole thread or script will be blocked while not player active

If you insert it in the right place and still Not working
You should fixed your code its messed up