While loop breaks after calling function

Idk what is happening, maybe you can go in debug mode. In debugmode, you can see every single step of your code. This is very usefull. And I should say: „Don‘t use a while wait() do loop“.

The DebugMode:
https://developer.roblox.com/en-us/articles/Lua-debugger

It is hard at first, but is very, very usefull with this sorrt of bugs.