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

How can you do click the Text Button every time?

How can you make to do things when you click first time ,second time , third time or more

Here is the Code: This is a local script on the textbutton

I want it to do something different whenever I want to click the Button 1st time,2nd time,3rd time. but it won't work.

local Frame = game.StarterGui.ScreenGui.Frame
script.Parent.Text = "Open Gui?"
script.Parent.MouseButton1Click:connect(function()
	if Frame.Visible == false then
	Frame.Visible = true
		script.Parent.Text = "Close Gui?"
	elseif	Frame.Visible == true then
		Frame.Visible = false
		script.Parent.Text = "Open Gui?"
	elseif script.Parent.Text == "Close Gui?" then
		script.Parent.Text = "3'rd time clicked"
	end
end)

1 comment

0

the "connect" is supposed to be "Connect"

1 answer

StarterGui is a replication container.

Much like StarterGear, this is not the active location of the Instances you wish to reference, they're actually moved over to an individualized folder located in the Player Object. In this case, it's a container called PlayerGui.

To properly interact with the local interface, you must gain access to this container through the Player Object appropriately, or simply reference the Instances in a way like so:

local Frame = script.Parent

local TextButton = Frame:WaitForChild("TextButton")


local function OnClick()
	TextButton.Text = (Frame.Visible and "Close Gui?" or "Open Gui")
	--// It's best to set the textual property to "Open Gui" as a default.
	---------------
	Frame.Visible = (not Frame.Visible)
	--// Simple Boolean logic to switch the visibility each click.
end


TextButton.MouseButton1Click:Connect(OnClick)

The code above applies a mimicked Ternary operation, I suggest you view the documentation about it as it is quite a useful tool!

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