Sometimes I am able to change a gui through a server script. Sometimes it does not work, Why is this? Could somebody explain the relationship of GUI's and the rest of the game
When you use Play Solo testing, there is no separation of server and client. If you'd like that, try Test Server instead.
The server can access the player's PlayerGui server-side, but when a client adds something to their PlayerGui (i.e. from game.StarterGui), the server doesn't know about it, so in practice the server only knows about GUIs it parented. Furthermore, the server should not ever attempt to change any GUI for any reason, that's the responsibility of the client.
Use a RemoteEvent
and fire the client, and let the client decide how to handle the GUI changes.
Helpful resource:
http://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events