How do i return a function when a gui button is clicked?

So, in the game im developing right now has a selection option and i have a exit button for the player

The problem being i can’t really tween it to go down since it uses a typewriting style which has sound whenever it was being typed out that would still play, i think the solution for this is to somehow make the exit button end the typewriting function

here is the code:

Click.MouseClick:Connect(function(player)
	
	visible = true
	Gui:TweenPosition(UDim2.new(0.2, 0, 0.1), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1, false)
	
	wait(0.5)
	
	typewrite(textlabel, "hi", 0.05)
	
	wait(1)
	
	typewrite(textlabel, "hi again", 0.05)
	
	wait(1)
end)

How do i make it so whenever any other GUI button is clicked it return that function?

1 Like

You can control it with a Boolean.

local shouldBreak = false

local function typewrite(message)
    for i = 1, #message, 1 do
        someText.Text = string.sub(message, 1, i)
        if shouldBreak then break end
        task.wait(0.0625) --some interval
    end
end

local function exit()
    shouldBreak = true
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.