TLDR: What is the correct way to add a gui to an object? How to store variables on entities?
Edit1: I also forgot to mention that I have not yet found a way to open the gui after the placement of the object, so a little help would be appreciated

This is very helpful, I just want to ask Is there a way to re-open the gui after the item was placed and the gui was closed. (like regular guis in the game)aubergine18 wrote:For opening GUI upon entity placement, listen to the on_built_entity event (assuming you only want the gui to open when player places the entity). In the event handler, check the event.created_entity.type and .name to determine if it's your entity that was built.
As for proper way to do entity GUI, there isn't one.
You have to check to see if a player's .selected == yourObject every few ticks in an on_tick event handler. Alternatively define a custom-input (keyboard shortcut) and when that event fires check to see if player has .selected == yourObject. Same goes for player walking away, the .selected will automatically leave the object if player is too far away (in fact, it will change as soon as player mouse is not over object). Checking via distance between player and object is another way to auto-close GUI.
To store data against objects, you can use LuaEntity.unit_number - a unique ID that most player-creatable entities have.
There's also Factorio Stdlib which has some useful features for storing data against entities.