I play in creative and build bases but I’ve had times where random people join and delete parts of my bases. How to I make it so people can’t join?
You can disable network play in the options. Press P (on PC) and set network play to "Off". If you do that, you are perfectly safe.
If you have network play enabled, then players can join your session via "Join random game". If a players joins your session, he is placed in a planetary system near you (or even in the same system). In the ingame chat, you will se the notification "[Player x] has joined your game", and if the player enters the same system as you, "[Player x] has entered the system".