Function when called crashes the editor and game

Nevermind I found the problem. Your solution was correct.