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

How do I create a ScreenGui and frame using instance.new? [closed]

Asked by 5 years ago

Basically, I would like to create a GUI using instance.new. I have tried a previous script which didn't work as it should have done, a grey box appeared however when I clicked on the frame in the explorer the grey box did not move along with it, confirming that it was not the frame.

Does anyone know how to get this to work? I would also like to specify a position and size.

Closed as Non-Descriptive by User#24403

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?

2 answers

Log in to vote
0
Answered by
Tizzel40 243 Moderation Voter
5 years ago

To Create and customize things in a script with "Instance.new you simply type "Instance.new(instance)"

then you can customize it too like this! :D

------------------------------------------------LOCAL SCRIPT I ASSUME...

local screengui = Instance.new("ScreenGui")

-----CUSTOMIZE THE SCREEN GUI

screengui.ResetOnSpawn = true

screengui.Enabled = true

screengui.Name = "TestGui"

----

local frame = Instance.new("Frame")

frame.Parent = screengui

frame.Position = UDim2.new(1,0,1,0)





------------------
0
You aren't supposed to just give away the answers, try to explain to them what's going on so they actually learn something. :\ OptimisticSide 199 — 5y
0
welp ... Rip my answer... Tizzel40 243 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You can create instances by using Instance.new()

local screengui = Instance.new("ScreenGui",game:GetService("StarterGui"))
local frame = Instance.new("Frame",screengui)

Now let's change up the object's names.

screengui.Name = "ExampleGUI"
frame.Name = "ExampleFrame"

Now that we have a ScreenGui and a Frame, let's change their size. UI Objects' size and position are a UDim2 value. You would type UDim2.new(), and type in the size/position just like you would in it's properties. For the sake of this demo, I'm just going to put the frame to cover half of the screen.

 frame.Size = UDim2.new(0.5,0,0.5,0)

Now let's change the position. Again, this will also be a UDim2 value. So you do the same thing as you did for the size. For the sake of this demo. I'm just going put the frame in the middle of the screen.

frame.Position = UDim2.new(0.25,0,0.25,0)

And, there you go. You now have a ScreenGui and a Frame.

If you enjoyed this tutorial, please accept the answer, so both of us can gain reputation! :)

0
Thanks! Just thought I would let you know that I think you forgot to parent the screengui to the startergui. When I did this all worked fine. Sir_funnyguy 4 — 5y