Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't this GUI show up when I start the game?

Asked by 7 years ago

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)

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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 Frameand the TextLabel. Remember to position them too! If this helped, please accept my answer! If it didn't please comment! Thanks!

0
Thanks! Why do I need to go "game:GetService" instead of just doing something like game.Players:ChildAdded/PlayerAdded and why do I need to put local infront of the variables? Sorry, I new at scripting. MEGALODAN01 7 — 7y
0
You don't have to put local infront of them, but it's reccommended because they are used inside of a function. Same with GetService, you don't have to but it's highly recommended. PyccknnXakep 1225 — 7y
Ad
Log in to vote
0
Answered by
65225 80
7 years ago
Edited 7 years ago

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!

Answer this question