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

Why doesnt my localscript make a textbutton but it makes a screengui and frame?

The localscript:

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)
if Frame.Visible == false then
	    Frame.Visible = true
	--the button
	TextButton.Parent = PlayerGui.ScreenGui.Frame
	TextButton.Position = UDim2.new(0, 0,0.09, 0)
	TextButton.Size = UDim2.new(0, 100,0, 100)
	if TextButton.Visible == false then
		    TextButton.Visible = true
		TextButton.MouseButton1Down:Connect(function()
print(fla)
	end)
end
end

2 comments

0

Why are you referencing the parents of the ScreenGui and Frame in that script? It's unneeded.

0

The 2nd parameter of Instance.new() is actually slower than just parenting it. @azulyzs

1 answer

✓ 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
    --the button
    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
--the button
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

0

I would like to mention, what the heck is fla?

0

you will never know

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