Hi! I'm pretty new to scripting ROBLOX Lua however I am fluent in other programming languages including: C, C++, Java, and Python. I have a script inside of an image button and I am trying to make it so that when you click the image button a new GUI will popup on the screen. My problem is not getting making a new frame because I check the explorer and it has made a new frame where I wanted it, the problem is that I can't see the frame or it's content! Here is the scripts contents:
local py = script.Parent local function buttonClicked() local frame = Instance.new("ScrollingFrame",game:GetService("StarterGui").GuiMain) frame.Position = UDim2.new(0.368, 0,0.151, 0) frame.Size = UDim2.new(0, 416,0, 455) frame.ZIndex = 3 frame.Visible = true local ide = Instance.new("TextBox",frame) ide.MultiLine = true print('clicked') end py.MouseButton1Click:Connect(buttonClicked)
Hey there.
Everything in your code works fine, the only issue is that you are trying to parent the new Frame into the StarterGui directory of GuiMain - although it may seem like it should go there, whenever a client joins the server, everything from StarterGui is replicated over to LocalPlayer.PlayerGui.
So to fix your code, all you need to do is use script.Parent.Parent. This will automatically set the directory to the PlayerGui and saves you needing to declare the player and the service. If you had wanted to take the LocalPlayer route you can declare the LocalPlayer (in a Local Script only) through
local Player = game.Players.LocalPlayer
Personally, I find it much easier to create a GUI using the studio editor, then setting the "Visible" property to false and when they click the button turn it true. It saves the hassle of having to create a GUI through a script . Feel free to ask anymore questions if need be.
I've left a sample of the fixed code below:
local py = script.Parent local function buttonClicked() local frame = Instance.new("ScrollingFrame", script.Parent.Parent) frame.Position = UDim2.new(0.368, 0,0.151, 0) frame.Size = UDim2.new(0, 416,0, 455) frame.ZIndex = 3 frame.Visible = true local ide = Instance.new("TextBox",frame) ide.MultiLine = true print('clicked') end py.MouseButton1Click:Connect(buttonClicked)
Here is your problem
local frame = Instance.new("ScrollingFrame",game:GetService("StarterGui").GuiMain)
You are trying to parent the frame to your StarterGui.GuiMain
StarterGui
is a container that holds all the Gui that will be cloned into the player's PlayerGui
on spawn (unless set to not do so)
So instead of parenting it in the GuiMain that is in StarterGui, parent it to the GuiMain that is in PlayerGui instead
you can get this, by getting first getting the player,
local player = game.Players.LocalPlayer
Did you know you can get the local player that way if you used local script? Its a really useful and convenient
Also i suggest using local script if you havent done so, for Gui
now change the previous piece of code into this
local frame = Instance.new("ScrollingFrame",player.PlayerGui.GuiMain)
That should fix your problem