✓ Accepted answer
You do not need the Frame.Visible and TextButton.Visible if statement, as it is already true when creating a Frame using Instance.new(). You can either set the Frame.Visible to be false or just remove the if statement entirely.
Way 1: Using the Frame.Visible and TextButton.Visible
local TextButton = Instance.new("TextButton")
local Frame = Instance.new("Frame")
local ScreenGui = Instance.new("ScreenGui")
local PlayerGui = game.Players.LocalPlayer.PlayerGui
ScreenGui.Parent = PlayerGui
Frame.Parent = ScreenGui
Frame.Position = UDim2.new(0, 0,0.09, 0)
Frame.Size = UDim2.new(0, 100,0, 100)
Frame.Visible = false
if Frame.Visible == false then
Frame.Visible = true
TextButton.Parent = PlayerGui.ScreenGui.Frame
TextButton.Position = UDim2.new(0, 0,0.09, 0)
TextButton.Size = UDim2.new(0, 100,0, 100)
TextButton.Visible = false
if TextButton.Visible == false then
TextButton.Visible = true
TextButton.MouseButton1Down:Connect(function()
print(fla)
end)
end
end
Way 2: Removing the if statements entirely.
local TextButton = Instance.new("TextButton")
local Frame = Instance.new("Frame")
local ScreenGui = Instance.new("ScreenGui")
local PlayerGui = game.Players.LocalPlayer.PlayerGui
ScreenGui.Parent = PlayerGui
Frame.Parent = ScreenGui
Frame.Position = UDim2.new(0, 0,0.09, 0)
Frame.Size = UDim2.new(0, 100,0, 100)
Frame.Visible = true
TextButton.Parent = PlayerGui.ScreenGui.Frame
TextButton.Position = UDim2.new(0, 0,0.09, 0)
TextButton.Size = UDim2.new(0, 100,0, 100)
TextButton.Visible = true
TextButton.MouseButton1Down:Connect(function()
print(fla)
end)
So the main reason why your script didn't work is because it will instantly set the visible property to true whenever you create a Frame or TextButton using Instance.new()
2 comments
Why are you referencing the parents of the ScreenGui and Frame in that script? It's unneeded.
The 2nd parameter of Instance.new() is actually slower than just parenting it. @azulyzs