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

How can I use a text button to open a GUI?

Asked by 10 years ago

This is my current code:

local gui = Workspace.ShopGui
local shopgui = Workspace.ShopGui

function onClick()
    Instance.new(shopgui) Players.Children.PlayerGui
end

script.Parent.MouseButton1Click:connect(onClick)

4 answers

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

Instance.new creates a brand new instance from the Roblox objects. If you clone the GUI and set it's parent to the local players GUI, then your shop GUI will appear on the players screen:

local shopgui = Workspace.ShopGui
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
    shopgui:Clone().Parent = player.PlayerGui
end)

This must be in a localscript to work! LocalPlayer only works when run in a local script.

0
OK. Ill try that and see what happens robogbot 5 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Do you want this in a StarterGui or Workspace?

Workspace I don't know. Just curious though.

Log in to vote
0
Answered by
HexC3D 830 Moderation Voter
10 years ago
local gui = Workspace.ShopGui
local shopgui = Workspace.ShopGui

function onClick()
   shopgui:Clone().Parent =  script.Parent.Parent.Parent.Parent -- Minus a parent if the textbutton is not in a frame
end

script.Parent.MouseButton1Click:connect(onClick)

What you did

local gui = Workspace.ShopGui
local shopgui = Workspace.ShopGui

function onClick()
    Instance.new(shopgui) -- There is not basic object named shopgui either way if it was a part this the it would be like "Part"
end

script.Parent.MouseButton1Click:connect(onClick)

Notice that idk if you have it inside a frame btw.

0
hey how do u become a contributer ._. TochiWasHere 10 — 10y
0
The first thing I did when I join was answer questions. HexC3D 830 — 10y
0
Also my question answered is 52. HexC3D 830 — 10y
0
thats the first thing i also did ._. TochiWasHere 10 — 10y
0
Glitch, Idk. HexC3D 830 — 10y
Log in to vote
0
Answered by 10 years ago
local GUI = Game.StarterGUI.GUI -- change the name of GUI if you want but it wont work unless its in StarterGUI.
local Frame = Instance.new("Frame")
local shopGUI = Game.StarterGUI.GUI.Frame -- Add a TextButton too.

Textbutton.Text = "" -- put the text you want between the "" -- You cant make Instance.new(shopgui) beacuse theres nothing Like it in Advanced Objects.


script.Parent.MouseButton1Click:connect(onClicked)

Answer this question