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 6 years ago
Edited 6 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 — 6y
0
Local Escaper65 6 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 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:

1local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("MyGui")
2local frame = MyGui.Frame
3local button = MyGui.TextButton
4 
5button.MouseButton1Click:Connect(function()
6    frame.Visible = not Frame.Visible
7end)

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

01local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("MyGui")
02local frame = MyGui.Frame
03local button = MyGui.TextButton
04local open = false
05 
06button.MouseButton1Click:Connect(function()
07    if open then
08        frame:TweenPosition(Udim2.new(0.3,0,1,0))
09    else
10        frame:TweenPosition(Udim2.new(0.3,0,.3,0))
11    end    
12end)
0
Ok. Thanks for the help :D Escaper65 6 — 6y
0
^ If it works, please accept it. Lugical 425 — 6y
Ad

Answer this question