✓ 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
is it local or server
Local