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

How to make a GUI visible through scripts?

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.

2 comments

0

is it local or server

0

Local

1 answer

✓ Accepted answer

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)

2 comments

0

Ok. Thanks for the help :D

0

^ If it works, please accept it.

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