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
game:GetService("UserInputService").InputBegan:connect(function(inputobject,gameProcessedEvent)
    --case
    if inputobject.KeyCode == Enum.KeyCode.Q then
        local file = Instance.new("ScreenGui")
        file.Parent = game.StarterGui
        local paper = Instance.new("Frame")
        paper.Size = UDim2.new(0,100,0,100)
        paper.Visible = true
        paper.Parent = file 
    end
end)

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

game:GetService("UserInputService").InputBegan:connect(function(inputobject,gameProcessedEvent)
    --case
    if inputobject.KeyCode == Enum.KeyCode.Q then
        local file = Instance.new("ScreenGui")
        file.Parent = game.Players.LocalPlayer.PlayerGui
        local paper = Instance.new("Frame")
        paper.Size = UDim2.new(0,100,0,100)
        paper.Visible = true
        paper.Parent = file 
    end
end)
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:

local paper = Instance.new("Frame")
paper.Visible = true
file.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:

local file = Instance.new("ScreenGui")
file.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:

game:GetService("UserInputService").InputBegan:connect(function(inputobject,gameProcessedEvent)
--case
    if inputobject.KeyCode == Enum.KeyCode.Q then
        local file = Instance.new("ScreenGui")
        file.Parent = game.Players.LocalPlayer.PlayerGui
        local paper = Instance.new("Frame")
        paper.Size = UDim2.new(0,100,0,100)
        paper.Visible = true
        paper.Parent = file
    end
end)

Answer this question