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

how to create a frame with instance.new()?

Asked by
Annon28 23
6 years ago
01game:GetService("UserInputService").InputBegan:connect(function(inputobject,gameProcessedEvent)
02    --case
03    if inputobject.KeyCode == Enum.KeyCode.Q then
04        local file = Instance.new("ScreenGui")
05        file.Parent = game.StarterGui
06        local paper = Instance.new("Frame")
07        paper.Size = UDim2.new(0,100,0,100)
08        paper.Visible = true
09        paper.Parent = file
10    end
11end)

it did create a screen gui and a frame but the frame is invisible. how to make the frame visible?

0
.-. you used startergui instead of playergui Elixcore 1337 — 6y
0
Yeah. TheMaster45611 2 — 6y

3 answers

Log in to vote
2
Answered by 6 years ago

you are creating the gui in startergui, because you are creating the gui on a key press, i assume this is DURING game, the startergui is basically just a storage service that clones all of its children into a player when he/she joins, move it to the PLAYERGUI instead, im also assuming you are using a localscript or else userinputservice wont work

01game:GetService("UserInputService").InputBegan:connect(function(inputobject,gameProcessedEvent)
02    --case
03    if inputobject.KeyCode == Enum.KeyCode.Q then
04        local file = Instance.new("ScreenGui")
05        file.Parent = game.Players.LocalPlayer.PlayerGui
06        local paper = Instance.new("Frame")
07        paper.Size = UDim2.new(0,100,0,100)
08        paper.Visible = true
09        paper.Parent = file
10    end
11end)
Ad
Log in to vote
0
Answered by
Nep_Ryker 131
6 years ago
Edited 6 years ago

To make the frame visible, it's as simple as this:

1local paper = Instance.new("Frame")
2paper.Visible = true
3file.BackgroundTransparency = 0 -- Just to make sure that it's really visible.

Oh, and I also suggest you make the ScreenGui's Enabled property to true by doing something like this:

1local file = Instance.new("ScreenGui")
2file.Enabled = true

Because the frame's visibility won't matter if the ScreenGui was Disabled. Also take note that if this doesn't work, it may be because you're using the StarterGui instead of the PlayerGui

0
And don't forget to set it's size. Nep_Ryker 131 — 6y
0
What he's doing wrong is line 5, he should set the gui parent to the PlayerGui Leamir 3138 — 6y
0
Exactly Nep_Ryker 131 — 6y
Log in to vote
0
Answered by
zblox164 531 Moderation Voter
6 years ago

Use PlayerGui instead of StarterGui. Example:

01game:GetService("UserInputService").InputBegan:connect(function(inputobject,gameProcessedEvent)
02--case
03    if inputobject.KeyCode == Enum.KeyCode.Q then
04        local file = Instance.new("ScreenGui")
05        file.Parent = game.Players.LocalPlayer.PlayerGui
06        local paper = Instance.new("Frame")
07        paper.Size = UDim2.new(0,100,0,100)
08        paper.Visible = true
09        paper.Parent = file
10    end
11end)

Answer this question