Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

1 comment

2 answers

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)

  

  

------------------

2 comments

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. :\

0

welp ... Rip my answer...

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! :)

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.