I wrote this script to create a GUI when the game starts, and when the game starts, in the explorer the GUI is created but it does not show up.
function createLoadingGui() newGUI = Instance.new("ScreenGui") newGUI.Parent = game.StarterGui newGUI.Name = "LoadingGui" print("LoadingGui created successfully") newFRAME = Instance.new("Frame") newFRAME.Parent = game.StarterGui.LoadingGui newFRAME.Name = "LoadingFrame" print("LoadingFrame created successfully") newTEXTLABEL = Instance.new("TextLabel") newTEXTLABEL.Parent = game.StarterGui.LoadingGui.LoadingFrame newTEXTLABEL.Name = "LoadingTEXTLABEL" print("LoadingTEXTLABEL created successfully") print("Function ran successfully") end game.Players.PlayerAdded:connect(createLoadingGui)
It's best to just design your GUI first, then use the Clone()
instance and parent it to the player who joins. But if you really want to create the GUI in your script, here's your improved script:
game:GetService("Players").PlayerAdded:Connect(function(Player) local Gui = Instance.new("ScreenGui",Player.PlayerGui) --You need to create it in the Player's player GUI. Gui.Name = "Loading Gui" local Frame = Instance.new("Frame", Gui) --Creating and parenting the Frame into the Gui at the same time. Frame.Name = "LoadingFrame" Frame.Size = UDim2.new(0,100,0,100) local TextLabel = Instance.new("TextLabel", Frame) TextLabel.Name = "LoadingTextLabel" TextLabel.Size = UDim2.new(0,100,0,100) end)
The problem was you didn't define the size of the Frame
and the TextLabel
. Remember to position them too! If this helped, please accept my answer! If it didn't please comment! Thanks!
You cannot parent an object inside of StarterGui since it's only user-defined. If you wanted to create a gui or parent a gui to a directory, use PlayerGui
.
game.Players.LocalPlayer.PlayerGui
Also, you can parent through using Instance
by adding a comma after the name.
Another problem was that whenever you create a new object, it starts with default properties, in this case; you'd need to resize the created gui to your liking using UDim2
.
game.Players.PlayerAdded:connect(function(player) local newGUI = Instance.new("ScreenGui",player.PlayerGui) newGUI.Name = "LoadingGui" local newFRAME = Instance.new("Frame",newGUI) newFRAME.Name = "LoadingFrame" newFRAME.Size = UDim2.new(0,100,0,100) local newTEXTLABEL = Instance.new("TextLabel",newFRAME) newTEXTLABEL.Name = "LoadingTEXTLABEL" newTEXTLABEL.Size = UDim2.new(0,50,0,50) end)
Hope I helped!