(kinda urgent) nested function return problem

so i have this script

game:GetService("ReplicatedStorage").DoorSYS.View.OnClientInvoke = function(): boolean
	show()
	local connection
	
	button.MouseButton1Click:Connect(function(): nil 
		close()
		if (connection) then connection:Disconnect() end
		return true 
	end)
	
	if textlabel.Visible then
		connection = UserInputService.InputBegan:Connect(function(input): nil
			if textlabel.isConsole.Value then
				if input.UserInputType == Enum.UserInputType.Gamepad1 and input.KeyCode == Enum.KeyCode.ButtonX then
					close()
					connection:Disconnect()
					return true
				end
			else
				if input.KeyCode == Enum.KeyCode.E then
					close()
					print("pressed e")
					connection:Disconnect()
					return true
				end
			end
		end)
	end
	
	while true do
		if End then
			End = false
			if (connection) then connection:Disconnect() end
			close()
			return false
		end
		task.wait()
	end
end

but if i press e it prints it but doesnt return true to the main function which is : boolean but instead returns to the function with : nil?

btw the loop does return false which proves the problem is that the functions are returning to themselves

Do any errors pop up in the Output on test? Also, is another script calling InvokeClient?

nope no errors everything working except the return true statements, there is invokeclient but no invokeserver

You’re creating a new function and a new scope here. Additionally, it’s in another thread.
That thread will return, but your main function won’t.

Also, your return type hint is wrong: you only ever return true from this function, so the return type is actually boolean. This doesn’t affect anything though.

1 Like

um so how to fix? 30charaterss