So I have this gui that I keep in Workspace. I am using it to learn a little more about scripting than I already do and the gui contains nothing.
What I want it to do is move from Workspace and into StarterGui once the game starts. So I placed a script into the gui and this is what I wrote in it:
game.Workspace.Gui.Parent = game.StarterGui
It works perfectly fine but what I was wondering is that if I move my gui for example in to Lighting or ServerScriptService would there be a script that automatically moves it into StarterGui? Without me retyping the script?
I have already tried messing around with .Parent and searched it up on the internet but I still cannot figure it out. Please help!
I suppose by moving you actually mean to change the ancestry of your Gui object in the DataModel -- Roblox's object tree?
If so then this line is perfectly valid.
About the Starter services:
Any object stored in the StarterPack service will be cloned into the player character's Backpack upon spawning/respawning;
Any object stored in the StarterGui service will be cloned into a "PlayerGui" container located in the player character upon spawning/respawning;
Any kind of script stored into StarterPlayer.StarterCharacterScripts will be cloned into the player character upon spawning/respawning;
Any kind of script stored into StarterPlayer.StarterPlayerScripts will be cloned into a "PlayerScripts" container located in the player's Player instance upon joining the game.
Note 1: The scripts in StarterPlayer.StarterCharacterScripts, unlike those from StarterPlayer.StarterPlayerScripts, will not persist when the player respawns (they will be removed upon death or reset).
Note 2: There is also a StarterGear container that is automatically inserted into every player's Player instance when joining the game. If a game allows gear, all of a player's appropriate gear will be inserted into StarterGear when the player joins the game. Whenever the player's Character spawns/respawns, all of the contents of that player's StarterGear will be copied over to the player's Backpack.
About other notable services:
Objects stored in the ReplicatedFirst service are sent before anything else to the clients upon joining the game, but never sent back to the server. This allows to preload assets such as textures, decals and sound during a custom loading screen instead of showing an incomplete level. Since the content stored in this server are never sent back to the server, it could probably also be used as a container for clientside only objects (objects that only a specific player can see and/or interact with).
The ReplicatedStorage service serves as a shared storage between the server and all clients at anytime. They can thus be used to store objects that are currently unused, or unloaded, by the server, such as a map for a minigame. Both scripts and localscripts can manipulate the objects stored in the ReplicatedStorage service.
The ServerStorage works similarly to the ReplicatedStorage service, except the objects are only stored on the server, and thus can only be manipulated by it. This is useful for two reasons. The first one is that network traffic won't be spent on transmitting the data for these objects to the players' client, resulting in faster loading times and gameplay. The obvious disadvantage, as already mentioned, is that these objects being in the cloud, localscripts -- scripts being executed only on the players' client -- cannot access them. The second reason, however, is that for the same reason, it can be used as a full hackerproof place to put your objects.
The ServerScriptService works similarly to the ServerStorage in that it is only located on the server. Just like the ServerStorage, It is also used as a full hackerproof place to put and organize scripts.
Other than that, I can't think of any container that might copy or move objects automatically without you scripting it.
Maybe you could write a child script of your Gui that would listen for the Gui's AncestryChanged event, like so:
local gui = script.Parent local function onAncestryChanged(child, parent) if parent ~= game.StarterGui then gui.Parent = game.StarterGui end end gui.AncestryChanged:connect(onAncestryChanged)
Edit: After re-reading the question, I decided to throw in some code.