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