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

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

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

✓ Accepted answer

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.

1 comment

0

OK. Ill try that and see what happens

Do you want this in a StarterGui or Workspace?

Workspace I don't know. Just curious though.

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.

5 comments

0

hey how do u become a contributer ._.

0

The first thing I did when I join was answer questions.

0

Also my question answered is 52.

0

thats the first thing i also did ._.

0

Glitch, Idk.

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)

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