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

How to make functions work more than once?

These two functions DO work, but they both only work once. The first adds a GUI and the second removes it, but it will only work once. How do I make it work more than once?

script.Parent.ClickDetector.MouseClick:connect(function(player)
	if not player.PlayerGui:FindFirstChild("ScreenGui") then
		local sc = Instance.new("ScreenGui", player.PlayerGui)
		wait(0.1)
		local fr = Instance.new("Frame", sc)
		fr.Size = UDim2.new(0, 100, 0, 100)
		fr.Position = UDim2.new(0, 750, 0, 250)
	end
end)

script.Parent.ClickDetector.MouseClick:connect(function(player)
	if player.PlayerGui.ScreenGui.Frame.Visible == true then
		player.PlayerGui.ScreenGui.Frame.Visible = false
	end
end)

1 answer

If you are using TextButtons, I would do something like this.

I'm not sure as what you are getting at because the question is somewhat vague.

local gui = script.TextButtonOne
local guitwo = script.TextButtonTwo

function onClick()
gui.Visible = false
gui.Visible  = true
end
gui.MouseButton1Click:connect(onClick)

function secondClick()
gui.Visible = true
gui.Visible = false
end
guiTwo.MouseButton1Click:connect(onClick)

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