Return out of parent function on click

hi i want to return out of a function when i click

this is kind of an example of what i want to do

local uis = game:GetService("UserInputService")

function whatiwanttomakework()
	uis.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			return "heyeasdrfds"
		end
	end)
end

function whatidonotwanttodo()
	local value
	
	uis.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			value = "hi"
		end
	end)
	
	for i=1, 30 do
		if value then
			break
		else
			wait(1)
		end
	end
	
	return value
end

function theonewhereineedittoreturnto()
	local str = whatidonotwanttodo()
	print(str)
end

how would i make the function whatiwanttomakework return whenever i click
my current method is the method i showed in the function whatidonotwanttodo and i dont want to do it because it has delay and i dont want that

ok bye bye

You can do this by having one function that is started and then waits on some variable. Then, a second function that receives clicks and sets that variable to let the other function continue. That function does not need to be an inner function. If you want there to be no overhead from waiting in a loop, you can use a bindable event to send the wakeup signal, calling :Wait() on the event from the function you want to return on click.

i will try the bindable event and mark solution if it works

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