✓ Accepted answer
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)
3 comments
Now when I click the image button the frame shows up but not the other components, why is that
Hey, I'm not on my PC to test for you but my best guess would be because you altered the Z-index. Try removing that line or adding a line to alter the Z-index of the other components.
Works, thanks!