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

How to make a GUI visible through scripts?

Asked by 5 years ago
Edited 5 years ago

I've been trying to make a guy appear through touch scripts but nothing seems to be working. I've tried enabling the screenGUI and the frame using:

"game.StarterGUI.ScreenGUI.Enabled = true" and "game.StarterGUI.ScreenGUI.Frame.Visible = true" (without the "")

But nothing happens.

0
is it local or server Z0ggg 20 — 5y
0
Local Escaper65 6 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

The problem here is that you are using StarterGui instead of PlayerGui. Also out of personal preference, I really do not like using the enabled property of screen guis.


PlayerGui


You may be asking, "why use the player gui?", what is the player gui?", and why can't I see the player gui?".

Well the player gui is an object inside the player that is created when a person joins the game. When that player joins the game, everything in StarterGui gets cloned into the PlayerGui. The reason you cant see it is because it doesnt exist when you are making the game,only when a player joins(or you use a local server / play solo).

With that said, lets see how you can use the PlayerGui:

local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("MyGui")
local frame = MyGui.Frame
local button = MyGui.TextButton

button.MouseButton1Click:Connect(function()
    frame.Visible = not Frame.Visible
end)

Note here that the PlayerGui isn't a service like StarterGui, but an object.

Important Note: modify gui elements in a local script, not a server script


other stuff


While the basics do work, you can add some flare to you on/off mechanism with the tweenPosition function

local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("MyGui")
local frame = MyGui.Frame
local button = MyGui.TextButton
local open = false

button.MouseButton1Click:Connect(function()
    if open then
        frame:TweenPosition(Udim2.new(0.3,0,1,0))
    else
        frame:TweenPosition(Udim2.new(0.3,0,.3,0))
    end     
end)
0
Ok. Thanks for the help :D Escaper65 6 — 5y
0
^ If it works, please accept it. Lugical 425 — 5y
Ad

Answer this question