Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make functions work more than once?

Asked by 8 years ago

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

Log in to vote
-2
Answered by 8 years ago

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)
Ad

Answer this question