Ok, I have been working a bit more and I got it to work but I don't understand why it only works in one way.
I use AddScriptSection this way:
scriptEngine->AddScriptSection(0, scriptName, scriptString.c_str(), (int)scriptString.length(), 0, false);
Now, when the scriptString variable is defined as static std::string everything works fine, the script builds fine and there are no problems, my script is executed just fine. But if it isn't static then the script fails to build with the error I posted on my first post.
Why does it work with static std::string and doesn't work with a normal std::string?